Opened 17 years ago

Closed 14 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

Description

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:
        pass
    
    def __unicode__(self):
        return u"%s the place" % self.name

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:
        pass

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

Change History (9)

comment:1 by Peter Baumgartner, 17 years ago

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

comment:2 by Peter Baumgartner, 17 years ago

Cc: sgt.hulka@… added

comment:3 by Jacob, 17 years ago

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

comment:4 by Peter Baumgartner, 17 years ago

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 by Jacob, 17 years ago

Triage Stage: UnreviewedAccepted

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

comment:6 by Peter Baumgartner, 17 years ago

confirmed in revision 7238

comment:7 by Alex Gaynor, 17 years ago

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 by Gabriel Hurley, 14 years ago

Severity: Normal
Type: Bug

comment:9 by Preston Timmons, 14 years ago

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