Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#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)

django_filter_ordering.zip (18.5 KB ) - added by Moritz Pfeiffer 6 years ago.
Sample project illustrating the problem. Navigate to /admin/foo/book and observer the order of Author in the list filters.
Screenshot 2019-05-06 at 15.49.17.jpg (243.1 KB ) - added by Moritz Pfeiffer 6 years ago.
Screenshot of RelatedOnlyFieldListFilter not ordering items.

Download all attachments as: .zip

Change History (15)

by Moritz Pfeiffer, 6 years ago

Attachment: django_filter_ordering.zip added

Sample project illustrating the problem. Navigate to /admin/foo/book and observer the order of Author in the list filters.

by Moritz Pfeiffer, 6 years ago

Screenshot of RelatedOnlyFieldListFilter not ordering items.

comment:1 by Carlton Gibson, 6 years ago

Triage Stage: UnreviewedAccepted

OK, yes, seems a reasonable suggestion if you'd like to work on it.

comment:2 by zeynel, 6 years ago

Owner: changed from nobody to zeynel
Status: newassigned

comment:3 by zeynel, 6 years ago

Has patch: set

comment:4 by Mariusz Felisiak, 6 years ago

Patch needs improvement: set

comment:5 by Althalus, 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 Mariusz Felisiak, 5 years ago

Version: 2.2master

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 Mariusz Felisiak, 5 years ago

Severity: NormalRelease blocker

I closed #30703 as a duplicate. It is a regression introduced in #29835.

comment:8 by Mariusz Felisiak, 5 years ago

Alternative PR.

Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:9 by tinodb, 5 years ago

I'd argue it is a regression. It worked before and is clearly broken now.

Any workarounds for the moment?

in reply to:  9 comment:10 by Mariusz Felisiak, 5 years ago

Replying to tinodb:

I'd argue it is a regression. It worked before and is clearly broken now.

Any workarounds for the moment?

Yes we marked this as a regression and release blocker (please check my previous comment).

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 00035672:

Fixed #30449 -- Fixed RelatedFieldListFilter/RelatedOnlyFieldListFilter to respect model's Meta.ordering.

Regression in 6d4e5feb79f7eabe8a0c7c4b87f25b1a7f87ca0b.

Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@…>

comment:12 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 8289fc55:

Refs #30449 -- Made RelatedOnlyFieldListFilter respect ModelAdmin.ordering.

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In c2732e6:

[2.2.x] Fixed #30449 -- Fixed RelatedFieldListFilter/RelatedOnlyFieldListFilter to respect model's Meta.ordering.

Regression in 6d4e5feb79f7eabe8a0c7c4b87f25b1a7f87ca0b.

Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@…>

Backport of 00035672a460b6eb5442d2837bc783f8af28c6f3 from master

Note: See TracTickets for help on using tickets.
Back to Top