Ticket #15517: patch_modeladmin_search_fields.diff

File patch_modeladmin_search_fields.diff, 1.2 KB (added by Fabian Büchler, 14 years ago)
  • django/contrib/admin/views/main.py

     
    254254                return "%s__icontains" % field_name
    255255
    256256        if self.search_fields and self.query:
     257            constructed_fields = [construct_search(str(field_name))
     258                                  for field_name in self.search_fields]
    257259            for bit in self.query.split():
    258                 or_queries = [models.Q(**{construct_search(str(field_name)): bit}) for field_name in self.search_fields]
     260                or_queries = [models.Q(**{field_name: bit})
     261                              for field_name in constructed_fields]
    259262                qs = qs.filter(reduce(operator.or_, or_queries))
    260263            if not use_distinct:
    261                 for search_field in self.search_fields:
     264                for search_field in constructed_fields:
    262265                    field_name = search_field.split('__', 1)[0]
    263266                    f = self.lookup_opts.get_field_by_name(field_name)[0]
    264267                    if hasattr(f, 'rel') and isinstance(f.rel, models.ManyToManyRel):
Back to Top