Ticket #11695: main.diff

File main.diff, 1.7 KB (added by Joshua Russo, 15 years ago)

From \contrib\admin\views

  • main.py

     
    6363        if ERROR_FLAG in self.params:
    6464            del self.params[ERROR_FLAG]
    6565
    66         self.order_field, self.order_type = self.get_ordering()
     66        self.order_field, self.order_type, self.ordering = self.get_ordering()
    6767        self.query = request.GET.get(SEARCH_VAR, '')
    6868        self.query_set = self.get_query_set()
    6969        self.get_results(request)
     
    138138        # manually-specified ordering from the query string.
    139139        ordering = self.model_admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
    140140
    141         if ordering[0].startswith('-'):
    142             order_field, order_type = ordering[0][1:], 'desc'
    143         else:
    144             order_field, order_type = ordering[0], 'asc'
     141        order_field = None
     142        order_type = None
    145143        if ORDER_VAR in params:
    146144            try:
    147145                field_name = self.list_display[int(params[ORDER_VAR])]
     
    166164                pass # Invalid ordering specified. Just use the default.
    167165        if ORDER_TYPE_VAR in params and params[ORDER_TYPE_VAR] in ('asc', 'desc'):
    168166            order_type = params[ORDER_TYPE_VAR]
    169         return order_field, order_type
     167        return order_field, order_type, ordering
    170168
    171169    def get_query_set(self):
    172170        qs = self.root_query_set
     
    216214        # Set ordering.
    217215        if self.order_field:
    218216            qs = qs.order_by('%s%s' % ((self.order_type == 'desc' and '-' or ''), self.order_field))
     217        elif self.ordering:
     218            qs = qs.order_by(*self.ordering)
    219219
    220220        # Apply keyword searches.
    221221        def construct_search(field_name):
Back to Top