Opened 12 years ago
Closed 3 years ago
#19721 closed New feature (fixed)
Django admin allows filtering using the field lookups such as "in", but it is impossible to include a value that contains a comma
Reported by: | aruseni | Owned by: | Shreya Bamne |
---|---|---|---|
Component: | contrib.admin | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | 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
The admin site allows you to filter the queryset in the changelist in a plenty of different ways. Notably, it allows you to filter the records by multiple values (if the field's value is one of the specified value options, then such record is considered matching).
For example, you can test it with a query string like this:
/admin/auth/user/?username__in=johnny,viola,gordon
Unfortunately, there is a big limitation at the moment: you can't include a value option that contains a comma (or a few).
The function that splits the string is prepare_lookup_value, found in contrib.admin.util.
Attachments (1)
Change History (17)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Has patch: | set |
---|
Not sure if it's a good idea... I've attached a patch which allows you to escape comma and backslash.
It will break any existing code searching for multiple backslashes (most likely not an issue).
comment:3 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Not sure if the backslash-escape is a good idea, or if we just need to provide a way to easily subclass the standard ListFilter and replace just the separator character (and then document that). Either way, it should be easier to filter on values including a comma.
comment:4 by , 12 years ago
Type: | Uncategorized → Bug |
---|
comment:6 by , 10 years ago
An interesting way to solve this would be to use getlist()
when pulling the filter arguments without an explicit filter lookup and if a list is found, use __in
rather than __exact
.
So to match the example given in the description, you'd be able to do:
/admin/auth/user/?username=johnny&username=viola,with,comma
comment:7 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Since this is a older ticket, I tried writing a small test in tests\admin_filters\tests.py
to confirm the issue and I was able to do so. I have started working on this ticket and assigning the ticket to me.
follow-up: 10 comment:9 by , 3 years ago
I am not sure if this is the right place to ask this, but I was wondering how long should I wait for my PR to get reviewed? I am new to the Django community, any help is appreciated. Thank you.
comment:10 by , 3 years ago
Replying to Shreya Bamne:
I am not sure if this is the right place to ask this, but I was wondering how long should I wait for my PR to get reviewed? I am new to the Django community, any help is appreciated. Thank you.
Unfortunately, you have to be patient. We try our best, but usually you have to wait a few weeks. Thanks for preparing a patch! See also FAQ: Contributing code.
comment:12 by , 3 years ago
Needs documentation: | set |
---|---|
Patch needs improvement: | set |
Type: | Bug → New feature |
comment:14 by , 3 years ago
Needs documentation: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Right now, the following workaround (besides monkey patching prepare_lookup_value) works for me:
I put it in list_filter of the ModelAdmin class:
And then including value options that contain commas becomes possible: