Code

Ticket #6933: django-6933-0.2.diff

File django-6933-0.2.diff, 957 bytes (added by diafour, 6 years ago)
Line 
1Index: main.py
2===================================================================
3--- main.py     (revision 7894)
4+++ main.py     (working copy)
5@@ -731,8 +731,15 @@
6             else:
7                 return "%s__icontains" % field_name
8 
9-        if self.lookup_opts.admin.search_fields and self.query:
10-            for bit in self.query.split():
11+        def query_split(query):
12+            first_bits = query.split('"')
13+            result_bits = first_bits[1::2]
14+                for bit in first_bits[0::2]:
15+                result_bits.extend( bit.split() )
16+            return result_bits
17+
18+        if self.lookup_opts.admin.search_fields and self.query:           
19+            for bit in query_split(self.query):
20                 or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.lookup_opts.admin.search_fields]
21                 other_qs = QuerySet(self.model)
22                 other_qs.dup_select_related(qs)