Ticket #3002: t3002-trunk-r7484.diff

File t3002-trunk-r7484.diff, 1.4 KB (added by Ramiro Morales, 17 years ago)

Slightly better patch fixing the bug, for trunk as of r7484

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

    diff -r 58d5564d1b5e django/contrib/admin/views/main.py
    a b class ChangeList(object):  
    716716                        qs = qs.select_related()
    717717                        break
    718718
    719         # Calculate lookup_order_field.
    720         # If the order-by field is a field with a relationship, order by the
    721         # value in the related table.
    722         lookup_order_field = self.order_field
    723         try:
    724             f = self.lookup_opts.get_field(self.order_field, many_to_many=False)
    725         except models.FieldDoesNotExist:
    726             pass
    727         else:
    728             if isinstance(f.rel, models.OneToOneRel):
    729                 # For OneToOneFields, don't try to order by the related object's ordering criteria.
    730                 pass
    731             elif isinstance(f.rel, models.ManyToOneRel):
    732                 rel_ordering = f.rel.to._meta.ordering and f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column
    733                 lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table, rel_ordering)
    734 
    735719        # Set ordering.
    736         qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field)
     720        qs = qs.order_by('%s%s' % (self.order_type == 'desc' and '-' or '', self.order_field))
    737721
    738722        # Apply keyword searches.
    739723        def construct_search(field_name):
Back to Top