Code

Ticket #2520: django_admin_change_list_order_bug.diff

File django_admin_change_list_order_bug.diff, 681 bytes (added by favo@…, 8 years ago)

Fixed #2520.

Line 
1Index: django/contrib/admin/views/main.py
2===================================================================
3--- django/contrib/admin/views/main.py  (revision 4645)
4+++ django/contrib/admin/views/main.py  (working copy)
5@@ -715,6 +715,8 @@
6             for bit in self.query.split():
7                 or_queries = [models.Q(**{'%s__icontains' % field_name: bit}) for field_name in self.lookup_opts.admin.search_fields]
8                 other_qs = QuerySet(self.model)
9+                if qs._select_related:
10+                    other_qs = other_qs.select_related()
11                 other_qs = other_qs.filter(reduce(operator.or_, or_queries))
12                 qs = qs & other_qs
13