Opened 17 years ago
Closed 5 years ago
#6933 closed New feature (fixed)
You cannot search with spaces if search_fields is declared with "^"
Reported by: | Owned by: | Alix Léger | |
---|---|---|---|
Component: | contrib.admin | Version: | newforms-admin |
Severity: | Normal | Keywords: | nfa-someday yandex-sprint ep2008 |
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 (last modified by )
That is. When search_fields is declared to "starts with" you cannot perform queries with spaces.
File contrib/admin/views/main.py; Line 326:
for bit in self.query.split(): or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.search_fields] other_qs = QuerySet(self.model) (...) qs = qs & other_qs
So, if for example i'm looking for "Hey dud" query will be:
qs.filter(field__startswith="Hey") & qs.filter(field__startswith("dud"))
Attachments (4)
Change History (23)
comment:1 by , 17 years ago
Keywords: | nfa-someday added |
---|
comment:2 by , 17 years ago
Description: | modified (diff) |
---|
comment:3 by , 16 years ago
Owner: | changed from | to
---|
by , 16 years ago
Attachment: | django-6933-0.diff added |
---|
comment:4 by , 16 years ago
Has patch: | set |
---|---|
Keywords: | yandex-sprint added |
django-6933-0.diff patch gives ability to use search strings with spaces.
You can define such strings with '"' (like google):
'hey dud' interprets like qs.filter(fieldstartswith="Hey") & qs.filter(fieldstartswith("dud"))
and '"hey dud"' interprets like qs.filter(fieldstartswith="hey dud")
The algorithm is very basic and don't check a string for paired quotes. So '"hey dud' works like '"hey dud"'.
by , 16 years ago
Attachment: | django-6933-0.2.diff added |
---|
by , 16 years ago
Attachment: | django-6933-0.3.diff added |
---|
comment:6 by , 16 years ago
Needs documentation: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Please take a look at django.utils.text.smart_split
for the splitting tool. And document this feature.
by , 16 years ago
Attachment: | django-6933-1.diff added |
---|
comment:9 by , 16 years ago
Keywords: | ep2008 added |
---|---|
Needs documentation: | unset |
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
thanks diafour. I just think that the doc patch should reffer to docs/admin.txt, but that's probably just a minor glitch
comment:10 by , 16 years ago
Needs tests: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:11 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Uncategorized |
#15203 was closed as a dupe. It reports the same problem but when the field name starts with =
. It has a much more current patch too.
comment:12 by , 14 years ago
Type: | Uncategorized → Bug |
---|
comment:13 by , 13 years ago
Easy pickings: | unset |
---|---|
Needs documentation: | set |
Type: | Bug → New feature |
UI/UX: | unset |
#17039 reported this again. Also given the current behavior is documented (https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields) I'd call this ticket a new feature, not a bug. Also, I don't see that the doc mentioning the inability to search exactly on phrases with spaces is changed by the newest patch here so I think there is some doc change needed in addition to what is added by the patch.
comment:16 by , 5 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Owner: | changed from | to
Status: | new → assigned |
comment:17 by , 5 years ago
Patch needs improvement: | set |
---|
comment:18 by , 5 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Code is same here on trunk and nfa, this should not block merge.