Code

Ticket #2870: order.patch

File order.patch, 1.4 KB (added by davidschein@…, 8 years ago)

patch

  • contrib/admin/views/main.py

     
    644644        # then check the object's default ordering. If neither of those exist, 
    645645        # order descending by ID by default. Finally, look for manually-specified 
    646646        # ordering from the query string. 
    647         ordering = lookup_opts.admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name] 
     647        ordering = lookup_opts.admin.ordering or lookup_opts.ordering or None #['-' + lookup_opts.pk.name] 
     648        if not ordering: return None, None 
    648649 
    649650        # Normalize it to new-style ordering. 
    650651        ordering = handle_legacy_orderlist(ordering) 
     
    708709            elif isinstance(f.rel, models.ManyToOneRel): 
    709710                rel_ordering = f.rel.to._meta.ordering and f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column 
    710711                lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table, rel_ordering) 
     712        if lookup_order_field: 
     713            # Set ordering. 
     714            qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field) 
    711715 
    712         # Set ordering. 
    713         qs = qs.order_by((self.order_type == 'desc' and '-' or '') + lookup_order_field) 
    714  
    715716        # Apply keyword searches. 
    716717        def construct_search(field_name): 
    717718            if field_name.startswith('^'):