Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#9795 closed (fixed)

One-to-one relation causes inappropriate filtering of other relations

Reported by: ubernostrum Owned by: brosner
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When a model has a OneToOneField pointing at it from another model, and that model has limit_choices_to set, then any related-object-selection displayed for that model will apply the limit_choices_to, regardless of whether the popup is being displayed to select an object for the relation which has limit_choices_to set.

Since this is somewhat hard to explain in words, I'll attach a minimal sample project which demonstrates the issue.

Attachments (1)

o2ofail.tgz (1.1 KB) - added by ubernostrum 5 years ago.
Minimal test-case app; see instructions in models.py.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

The source of the bug, incidentally, is almost certainly line 240 of contrib/admin/views/main.py; I'm just not sure yet how to fix this so that it "knows" which model you were adding/editing when you clicked for the popup (since it should only apply limit_choices_to when adding/editing the model which has the OneToOneField).

Changed 5 years ago by ubernostrum

Minimal test-case app; see instructions in models.py.

comment:2 Changed 5 years ago by brosner

  • Owner changed from nobody to brosner
  • Status changed from new to assigned

comment:3 Changed 5 years ago by Alex

brosner, I've reviewed this, and as far as I can tell this can't be fixed with the current structure, since the ChangeList view doesn't know where it's coming from, this would probably best be fixed in your branch so it can be properly rearchitected.

comment:4 Changed 5 years ago by ubernostrum

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [9641]) Fixed #9795: Since related-object selection widgets take limit_choices_to into account, the offending code is no longer necessary and can simply be removed.

comment:5 Changed 5 years ago by ubernostrum

(In [9642]) [1.0.X] Fixed #9795: Since related-object selection widgets take limit_choices_to into account, the offending code is no longer necessary and can simply be removed. Was [9641] in trunk.

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.