Opened 15 years ago

Closed 15 years ago

Last modified 15 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: no UI/UX: no

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 15 years ago.
Minimal test-case app; see instructions in models.py.

Download all attachments as: .zip

Change History (6)

comment:1 by James Bennett, 15 years ago

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

by James Bennett, 15 years ago

Attachment: o2ofail.tgz added

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

comment:2 by Brian Rosner, 15 years ago

Owner: changed from nobody to Brian Rosner
Status: newassigned

comment:3 by Alex Gaynor, 15 years ago

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

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

(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