Code

Opened 7 years ago

Closed 3 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:

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

Attachments (0)

Change History (9)

comment:1 Changed 7 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 7 years ago by baumer1122

  • Cc sgt.hulka@… added

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

confirmed in revision 7238

comment:7 Changed 6 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 3 years ago by gabrielhurley

  • Severity set to Normal
  • Type set to Bug

comment:9 Changed 3 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.