Ticket #12875: ticket_12875.diff

File ticket_12875.diff, 2.0 KB (added by Manuel Saelices, 15 years ago)
  • django/contrib/admin/options.py

     
    259259        )
    260260        return urlpatterns
    261261
     262    def get_ordering(self, request):
     263        return None
     264
    262265    def urls(self):
    263266        return self.get_urls()
    264267    urls = property(urls)
  • django/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.get_ordering(request)
    6767        self.query = request.GET.get(SEARCH_VAR, '')
    6868        self.query_set = self.get_query_set()
    6969        self.get_results(request)
     
    130130        self.multi_page = multi_page
    131131        self.paginator = paginator
    132132
    133     def get_ordering(self):
     133    def get_ordering(self, request):
    134134        lookup_opts, params = self.lookup_opts, self.params
    135         # For ordering, first check the "ordering" parameter in the admin
     135        # For ordering, first check if exists the "get_ordering" method
     136        # in model admin, then check the "ordering" parameter in admin
    136137        # options, then check the object's default ordering. If neither of
    137138        # those exist, order descending by ID by default. Finally, look for
    138139        # manually-specified ordering from the query string.
    139         ordering = self.model_admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
     140        ordering = self.model_admin.get_ordering(request) or self.model_admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
    140141
    141142        if ordering[0].startswith('-'):
    142143            order_field, order_type = ordering[0][1:], 'desc'
Back to Top