Ticket #6933: django-6933-1.diff

File django-6933-1.diff, 1.9 KB (added by diafour, 16 years ago)
  • django/contrib/admin/views/main.py

     
    1111from django.db.models.query import QuerySet
    1212from django.http import Http404, HttpResponse, HttpResponseRedirect
    1313from django.utils.html import escape
    14 from django.utils.text import capfirst, get_text_list
     14from django.utils.text import capfirst, get_text_list, smart_split
    1515from django.utils.encoding import force_unicode, smart_str
    1616from django.utils.translation import ugettext as _
    1717from django.utils.safestring import mark_safe
     
    732732                return "%s__icontains" % field_name
    733733
    734734        if self.lookup_opts.admin.search_fields and self.query:
    735             for bit in self.query.split():
     735            for bit in smart_split(self.query):
     736                bit = bit.strip("\'\"")
    736737                or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.lookup_opts.admin.search_fields]
    737738                other_qs = QuerySet(self.model)
    738739                other_qs.dup_select_related(qs)
  • docs/model-api.txt

     
    16261626    WHERE (first_name ILIKE '%john%' OR last_name ILIKE '%john%')
    16271627    AND (first_name ILIKE '%lennon%' OR last_name ILIKE '%lennon%')
    16281628
     1629.. admonition:: Note
     1630
     1631    To search for phrase with a space use quotes. Supports double and
     1632    single quotes, and supports escaping quotes with backslashes.
     1633    ``"Foo bar" boo`` searches for ``foo bar`` and ``boo`` while
     1634    ``foo bar boo`` searches for ``foo`` and ``bar`` and ``foo``.
     1635   
    16291636For faster and/or more restrictive searches, prefix the field name
    16301637with an operator:
    16311638
Back to Top