Ticket #2559: django-search_fields-operators.diff

File django-search_fields-operators.diff, 1.3 KB (added by Andy Dustman <farcepest@…>, 18 years ago)

Implementation

  • django/contrib/admin/views/main.py

     
    711711        qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field)
    712712
    713713        # Apply keyword searches.
     714        def construct_search(field_name):
     715            if field_name.startswith('^'):
     716                return "%s__istartswith" % field_name[1:]
     717            elif field_name.startswith('='):
     718                return "%s__iexact" % field_name[1:]
     719            elif field_name.startswith('@'):
     720                return "%s__search" % field_name[1:]
     721            else:
     722                return "%s__icontains" % field_name
     723           
    714724        if self.lookup_opts.admin.search_fields and self.query:
    715725            for bit in self.query.split():
    716                 or_queries = [models.Q(**{'%s__icontains' % field_name: bit}) for field_name in self.lookup_opts.admin.search_fields]
     726                or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.lookup_opts.admin.search_fields]
    717727                other_qs = QuerySet(self.model)
    718728                other_qs = other_qs.filter(reduce(operator.or_, or_queries))
    719729                qs = qs & other_qs
Back to Top