Ticket #2559: django-search_fields-operators.diff
File django-search_fields-operators.diff, 1.3 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/views/main.py
711 711 qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field) 712 712 713 713 # 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 714 724 if self.lookup_opts.admin.search_fields and self.query: 715 725 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] 717 727 other_qs = QuerySet(self.model) 718 728 other_qs = other_qs.filter(reduce(operator.or_, or_queries)) 719 729 qs = qs & other_qs