Code

Opened 3 years ago

Closed 3 years ago

#15673 closed New feature (fixed)

Allow limit_choices_to to use a tuple for __in filters

Reported by: EnTeQuAk 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 EnTeQuAk 3 years ago.
Diff with proper testcase and fix for this ticket

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by EnTeQuAk

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 3 years ago by EnTeQuAk

Diff with proper testcase and fix for this ticket

comment:2 Changed 3 years ago by mk

  • Component changed from Uncategorized to django.contrib.admin
  • Triage Stage changed from Unreviewed to Ready 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 3 years ago by lukeplant

  • Type set to New feature

comment:4 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:5 Changed 3 years ago by aaugustin

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 3 years ago by jezdez

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

In [16078]:

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

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.