Ticket #3002: ticket-3002.diff

File ticket-3002.diff, 1.2 KB (added by ramiro <rm0 _at_ gmx.net>, 18 years ago)

A better version of the proposed patch, this time as an attachment

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

    old new  
    693693                        qs = qs.select_related()
    694694                        break
    695695
    696         # Calculate lookup_order_field.
    697         # If the order-by field is a field with a relationship, order by the
    698         # value in the related table.
    699696        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             pass
    704         else:
    705             if isinstance(f.rel, models.OneToOneRel):
    706                 # For OneToOneFields, don't try to order by the related object's ordering criteria.
    707                 pass
    708             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.column
    710                 lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table, rel_ordering)
    711697
    712698        # Set ordering.
    713699        qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field)
Back to Top