Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9795 closed (fixed)

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

Reported by: James Bennett Owned by: Brian Rosner
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 James Bennett 8 years ago.
Minimal test-case app; see instructions in models.py.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 8 years ago by James Bennett

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

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

Attachment: o2ofail.tgz added

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

comment:2 Changed 8 years ago by Brian Rosner

Owner: changed from nobody to Brian Rosner
Status: newassigned

comment:3 Changed 8 years ago by Alex Gaynor

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

Resolution: fixed
Status: assignedclosed

(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 8 years ago by James Bennett

(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.

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