Ticket #3002: ticket-3002.diff
File ticket-3002.diff, 1.2 KB (added by , 18 years ago) |
---|
-
trunk/django/contrib/admin/views/main.py
old new 693 693 qs = qs.select_related() 694 694 break 695 695 696 # Calculate lookup_order_field.697 # If the order-by field is a field with a relationship, order by the698 # value in the related table.699 696 lookup_order_field = self.order_field 700 try:701 f = self.lookup_opts.get_field(self.order_field, many_to_many=False)702 except models.FieldDoesNotExist:703 pass704 else:705 if isinstance(f.rel, models.OneToOneRel):706 # For OneToOneFields, don't try to order by the related object's ordering criteria.707 pass708 elif isinstance(f.rel, models.ManyToOneRel):709 rel_ordering = f.rel.to._meta.ordering and f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column710 lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table, rel_ordering)711 697 712 698 # Set ordering. 713 699 qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field)