Code

Ticket #7099: t7099-nf-a-r7484.diff

File t7099-nf-a-r7484.diff, 1.8 KB (added by ramiro, 6 years ago)

Patch fixing the bug, for nf-a as of r7484

Line 
1diff -r 20337e249537 django/contrib/admin/views/main.py
2--- a/django/contrib/admin/views/main.py        Sun Apr 27 19:37:50 2008 -0300
3+++ b/django/contrib/admin/views/main.py        Sun Apr 27 20:57:00 2008 -0300
4@@ -282,31 +282,8 @@ class ChangeList(object):
5                         qs = qs.select_related()
6                         break
7 
8-        # Calculate lookup_order_field.
9-        # If the order-by field is a field with a relationship, order by the
10-        # value in the related table.
11-        lookup_order_field = self.order_field
12-        order_type = self.order_type == 'desc' and '-' or ''
13-        try:
14-            f = self.lookup_opts.get_field(self.order_field, many_to_many=False)
15-        except models.FieldDoesNotExist:
16-            pass
17-        else:
18-            if isinstance(f.rel, models.OneToOneRel):
19-                # For OneToOneFields, don't try to order by the related object's ordering criteria.
20-                pass
21-            elif isinstance(f.rel, models.ManyToOneRel):
22-                rel_ordering = f.rel.to._meta.ordering and f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column
23-                if rel_ordering[0] == '-':
24-                    rel_ordering = rel_ordering[1:]
25-                    order_type = not order_type and '-' or ''
26-                lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table, rel_ordering)
27-                # FIXME: Must use select_related() becuase the lookup field may
28-                # be in a table not otherwise referenced yet.
29-                qs = qs.select_related()
30-
31         # Set ordering.
32-        qs = qs.order_by(order_type + lookup_order_field)
33+        qs = qs.order_by('%s%s' % (self.order_type == 'desc' and '-' or '', self.order_field))
34 
35         # Apply keyword searches.
36         def construct_search(field_name):