Opened 15 years ago
Closed 15 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)
Change History (7)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
| Component: | Uncategorized → django.contrib.admin |
|---|---|
| Triage Stage: | Unreviewed → 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 by , 15 years ago
| Type: | → New feature |
|---|
comment:4 by , 15 years ago
| Severity: | → Normal |
|---|
comment:5 by , 15 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:
- experimentally, both tuples and lists work.
- the doc says "a given list"; in the context, that means "an iterable of values" rather than "a Python list object". See http://docs.djangoproject.com/en/dev/ref/models/querysets/#in
Since this patch is consistent with the docs and with other parts of the framework, I also consider it is RFC.
sorry for the bad formatting...
If one is to use
myfield = models.ForeignKey(MyModel, limit_choices_to={'valuein': ('one', 'two')})this fails if rendered withdjango.contrib.admin.widgets:url_params_from_lookup_dictI attached a Diff that adds a unittest and the fix.