Opened 9 years ago

Closed 5 years ago

#5497 closed Bug (worksforme)

OneToOneField limit_choices_to filters parent set in admin

Reported by: baumer1122 Owned by: nobody
Component: contrib.admin Version: master
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:


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 9 years ago by baumer1122

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 9 years ago by baumer1122

  • Cc sgt.hulka@… added

comment:3 Changed 9 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 8 years ago by baumer1122

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 8 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

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

comment:6 Changed 8 years ago by baumer1122

confirmed in revision 7238

comment:7 Changed 8 years ago by Alex

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 5 years ago by gabrielhurley

  • Severity set to Normal
  • Type set to Bug

comment:9 Changed 5 years ago by prestontimmons

  • Easy pickings unset
  • Resolution set to worksforme
  • Status changed from new to closed

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