Ticket #2818: search_distinct.2.diff

File search_distinct.2.diff, 728 bytes (added by Andy Dustman <farcepest@…>, 18 years ago)

Use distinct() only when joined search fields are present

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

     
    731731                    other_qs = other_qs.select_related()
    732732                other_qs = other_qs.filter(reduce(operator.or_, or_queries))
    733733                qs = qs & other_qs
     734            for field_name in self.lookup_opts.admin.search_fields:
     735                if len(field_name.split("__")) > 1:
     736                    qs = qs.distinct()
     737                    break
    734738
    735739        if self.opts.one_to_one_field:
    736740            qs = qs.complex_filter(self.opts.one_to_one_field.rel.limit_choices_to)
Back to Top