Ticket #10212: 10212.diff

File 10212.diff, 1.1 KB (added by kyle.fox@…, 16 years ago)

Patch for #10212 - Allows order_by in ModelAdmin.queryset

  • contrib/admin/views/main.py

     
    131131
    132132    def get_ordering(self):
    133133        lookup_opts, params = self.lookup_opts, self.params
    134         # For ordering, first check the "ordering" parameter in the admin
    135         # options, then check the object's default ordering. If neither of
     134        # For ordering, first check if `root_query_set` has an order_by clause.
     135        # Then check the "ordering" parameter in the admin options,
     136        # then check the object's default ordering. If none of
    136137        # those exist, order descending by ID by default. Finally, look for
    137138        # manually-specified ordering from the query string.
    138         ordering = self.model_admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
     139        ordering = self.root_query_set.query.order_by or self.model_admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
    139140
    140141        if ordering[0].startswith('-'):
    141142            order_field, order_type = ordering[0][1:], 'desc'
Back to Top