Opened 16 years ago
Closed 14 years ago
#10212 closed (duplicate)
Admin ChangeList doesn't apply 'order_by' clause specified by ModelAdmin.queryset
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | 1.0 |
Severity: | Keywords: | ChangeList, admin, ordering, queryset | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Overriding ModelAdmin.queryset
to apply an explicit order_by
clause doesn't work. Although it looks like it, the example shown won't order by '-birth_date'
class PersonAdmin(admin.ModelAdmin): list_display = ['name', 'birth_date'] def queryset(self, request): return Person.objects.order_by('-birth_date') admin.site.register(Person, PersonAdmin)
This patch changes ChangeList.get_ordering
to respect any ordering clause that is present on the queryset.
Attachments (2)
Change History (7)
by , 16 years ago
Attachment: | 10212.diff added |
---|
comment:1 by , 16 years ago
Component: | Uncategorized → django.contrib.admin |
---|---|
Has patch: | set |
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
Is there a reason not to just use ordering
on the ModelAdmin
?
comment:3 by , 16 years ago
Yes -- I'm using django-mptt, which has a custom manager to calculates the ordering of objects according to hierarchy.
Currently, if you try to use a custom manager which defines it's own ordering, the admin *drops* that order by clause.
comment:4 by , 16 years ago
I also hit this issue. Would be easier to solve with the patch in #9749.
by , 16 years ago
Attachment: | admin_ordering.diff added |
---|
More general patch. Also allows multi-level ordering and ordering given in query_set.extra().
Patch for #10212 - Allows order_by in ModelAdmin.queryset