Opened 6 years ago

Closed 6 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: master
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: UI/UX:

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 6 years ago.
Diff with proper testcase and fix for this ticket

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by Christopher Grebs

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.

Changed 6 years ago by Christopher Grebs

Attachment: t15673.diff added

Diff with proper testcase and fix for this ticket

comment:2 Changed 6 years ago by Matthias Kestenholz

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 Changed 6 years ago by Luke Plant

Type: New feature

comment:4 Changed 6 years ago by Luke Plant

Severity: Normal

comment:5 Changed 6 years ago by Aymeric Augustin

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 Changed 6 years ago by Jannis Leidel

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