From a1e4b15f15d7807ddd35c0172b738a6e399235f6 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 28 Apr 2008 02:40:57 +0000 Subject: [PATCH] Fixed #3002 -- Fixed a problem with ordering by related models in the admin interface. Patch from Ramiro Morales. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7491 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/views/main.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 2b7a690a83..515dea56a1 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -716,24 +716,9 @@ class ChangeList(object): qs = qs.select_related() break - # Calculate lookup_order_field. - # If the order-by field is a field with a relationship, order by the - # value in the related table. - lookup_order_field = self.order_field - try: - f = self.lookup_opts.get_field(self.order_field, many_to_many=False) - except models.FieldDoesNotExist: - pass - else: - if isinstance(f.rel, models.OneToOneRel): - # For OneToOneFields, don't try to order by the related object's ordering criteria. - pass - elif isinstance(f.rel, models.ManyToOneRel): - rel_ordering = f.rel.to._meta.ordering and f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column - lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table, rel_ordering) - # Set ordering. - qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field) + if self.order_field: + qs = qs.order_by('%s%s' % ((self.order_type == 'desc' and '-' or ''), self.order_field)) # Apply keyword searches. def construct_search(field_name):