#30449 closed Bug (fixed)
Ordering problem in admin.RelatedFieldListFilter and admin.RelatedOnlyFieldListFilter
Reported by: | Moritz Pfeiffer | Owned by: | zeynel |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Release blocker | Keywords: | RelatedFieldListFilter, RelatedOnlyFieldListFilter, ordering |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | yes |
Description
RelatedFieldListFilter doesn't fall back to the ordering defined in Model._meta.ordering.
Ordering gets set to an empty tuple in https://github.com/django/django/blob/2.2.1/django/contrib/admin/filters.py#L196 and unless ordering is defined on the related model's ModelAdmin class it stays an empty tuple. IMHO it should fall back to the ordering defined in the related model's Meta.ordering field.
RelatedOnlyFieldListFilter doesn't order the related model at all, even if ordering is defined on the related model's ModelAdmin class.
That's because the call to field.get_choices https://github.com/django/django/blob/2.2.1/django/contrib/admin/filters.py#L422 omits the ordering kwarg entirely.
Attachments (2)
Change History (15)
by , 6 years ago
Attachment: | django_filter_ordering.zip added |
---|
by , 6 years ago
Attachment: | Screenshot 2019-05-06 at 15.49.17.jpg added |
---|
Screenshot of RelatedOnlyFieldListFilter not ordering items.
comment:1 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
OK, yes, seems a reasonable suggestion if you'd like to work on it.
comment:2 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 6 years ago
Has patch: | set |
---|
comment:4 by , 5 years ago
Patch needs improvement: | set |
---|
comment:5 by , 5 years ago
Patch needs improvement: | unset |
---|
Hello. We've updated our django recently and faced this bug. For me it seems like a quite big regression.
As I see in PR, patch was updated and appropriate tests were added too so I suggest to consider including it in 2.2.4 and backporting to (at least) 2.1.
comment:6 by , 5 years ago
Version: | 2.2 → master |
---|
As far as I'm concerned it's not a regression and doesn't qualify for a backport. It's on my list and should be fixed in Django 3.0.
comment:7 by , 5 years ago
Severity: | Normal → Release blocker |
---|
follow-up: 10 comment:9 by , 5 years ago
I'd argue it is a regression. It worked before and is clearly broken now.
Any workarounds for the moment?
Sample project illustrating the problem. Navigate to /admin/foo/book and observer the order of Author in the list filters.