Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit a1e4b15f15d7807ddd35c0172b738a6e399235f6 1 parent 356dfd5
Malcolm Tredinnick authored April 28, 2008

Showing 1 changed file with 2 additions and 17 deletions. Show diff stats Hide diff stats

  1. 19  django/contrib/admin/views/main.py
19  django/contrib/admin/views/main.py
@@ -716,24 +716,9 @@ def get_query_set(self):
716 716
                         qs = qs.select_related()
717 717
                         break
718 718
 
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  
-
735 719
         # Set ordering.
736  
-        qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field)
  720
+        if self.order_field:
  721
+            qs = qs.order_by('%s%s' % ((self.order_type == 'desc' and '-' or ''), self.order_field))
737 722
 
738 723
         # Apply keyword searches.
739 724
         def construct_search(field_name):

0 notes on commit a1e4b15

Please sign in to comment.
Something went wrong with that request. Please try again.