Opened 13 years ago

Closed 13 years ago

#15673 closed New feature (fixed)

Allow limit_choices_to to use a tuple for __in filters

Reported by: Christopher Grebs Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: cg@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If one is to use myfield = models.ForeignKey(MyModel, limit_choices_to={'valuein': ('one', 'two')}) this fails if rendered with django.contrib.admin.widgets:url_params_from_lookup_dict

I attached a Diff that adds a unittest and the fix.

Attachments (1)

t15673.diff (1.9 KB ) - added by Christopher Grebs 13 years ago.
Diff with proper testcase and fix for this ticket

Download all attachments as: .zip

Change History (7)

comment:1 by Christopher Grebs, 13 years ago

sorry for the bad formatting...

If one is to use myfield = models.ForeignKey(MyModel, limit_choices_to={'valuein': ('one', 'two')}) this fails if rendered with django.contrib.admin.widgets:url_params_from_lookup_dict

I attached a Diff that adds a unittest and the fix.

by Christopher Grebs, 13 years ago

Attachment: t15673.diff added

Diff with proper testcase and fix for this ticket

comment:2 by Matthias Kestenholz, 13 years ago

Component: Uncategorizeddjango.contrib.admin
Triage Stage: UnreviewedReady for checkin

I think this makes lots of sense. The patch fixes the problem and provides a testcase for it. (Applied & ran the testsuite)

comment:3 by Luke Plant, 13 years ago

Type: New feature

comment:4 by Luke Plant, 13 years ago

Severity: Normal

comment:5 by Aymeric Augustin, 13 years ago

Patch is off by one line in a file, but it applies and the whole test suite passes.

Based on the docs, the limit_choices_to argument of ForeignKey must be a dictionary that defines acceptable keyword arguments for filter(). So I checked what filter() would accept in a <field>__in=... argument:

Since this patch is consistent with the docs and with other parts of the framework, I also consider it is RFC.

comment:6 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16078]:

Fixed #15673 -- Allow limit_choices_to to use a tuple for in filters. Thanks, EnTeQuAk.

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