Opened 15 years ago

Closed 11 years ago

#5497 closed Bug (worksforme)

OneToOneField limit_choices_to filters parent set in admin

Reported by: Peter Baumgartner Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords: onetoonefield
Cc: sgt.hulka@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Setting limit_choices_to on a OneToOneField filters the queryset displayed in admin for the parent field.

Seeing this in current SVN (6304)

Example models:

from django.db import models

class Place(models.Model):
    name = models.CharField(max_length=50)
    class Admin:
    def __unicode__(self):
        return u"%s the place" %

class Restaurant(models.Model):
    place = models.OneToOneField(Place, limit_choices_to={'name': 'My Place'})
    serves_hot_dogs = models.BooleanField()
    serves_pizza = models.BooleanField()

    class Admin:

    def __unicode__(self):
        return u"%s the restaurant" %

Change History (9)

comment:1 Changed 15 years ago by Peter Baumgartner

To further clarify, in the above example, only places with the name 'My Place' will be displayed in admin.

comment:2 Changed 15 years ago by Peter Baumgartner

Cc: sgt.hulka@… added

comment:3 Changed 15 years ago by Jacob

I'm a bit confused -- limit_choices_to is supposed to limit the choices... what did you expect to happen?

comment:4 Changed 15 years ago by Peter Baumgartner

From the example above, I would expect limit_choices_to to limit the Place choices in the Restaurant model.

The unexpected behavior comes when viewing Place objects in admin. It only displays objects that match the limit_choices_to that is set in Restaurant

I haven't checked whether this still occurs in trunk.

comment:5 Changed 15 years ago by Jacob

Triage Stage: UnreviewedAccepted

Please do check if this still applies on trunk and close the ticket if it doesn't.

comment:6 Changed 15 years ago by Peter Baumgartner

confirmed in revision 7238

comment:7 Changed 15 years ago by Alex Gaynor

Does anyone know if this occurs in newforms-admin, this seems like a problem with the admin filtering, not necessarily the model/queryset.

comment:8 Changed 12 years ago by Gabriel Hurley

Severity: Normal
Type: Bug

comment:9 Changed 11 years ago by Preston Timmons

Easy pickings: unset
Resolution: worksforme
Status: newclosed

I tested this against [16164] using the models above in the current admin. The admin list display for Places worked properly for me. I'm closing this as working in newforms-admin.

Note: See TracTickets for help on using tickets.
Back to Top