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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30449>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* 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.
* Attachment "Screenshot 2019-05-06 at 15.49.17.jpg" added.
Screenshot of RelatedOnlyFieldListFilter not ordering items.
* stage: Unreviewed => Accepted
Comment:
OK, yes, seems a reasonable suggestion if you'd like to work on it.
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:1>
* status: new => assigned
* owner: nobody => zeynel
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:4>
* needs_better_patch: 1 => 0
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:5>
* version: 2.2 => master
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:6>
* severity: Normal => Release blocker
Comment:
I closed #30703 as a duplicate. It is a regression introduced in #29835.
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:7>
Comment (by felixxm):
Alternate [https://github.com/django/django/pull/11661 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:8>
Comment (by tinodb):
I'd argue it ''is'' a regression. It worked before and is clearly broken
now.
Any workarounds for the moment?
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:9>
Comment (by felixxm):
Replying to [comment:9 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 [https://code.djangoproject.com/ticket/30449#comment:7 comment]).
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:10>
Comment (by felixxm):
`RelatedOnlyFieldListFilter` part is not a regression because it never
worked.
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:11>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"00035672a460b6eb5442d2837bc783f8af28c6f3" 00035672]:
{{{
#!CommitTicketReference repository=""
revision="00035672a460b6eb5442d2837bc783f8af28c6f3"
Fixed #30449 -- Fixed RelatedFieldListFilter/RelatedOnlyFieldListFilter to
respect model's Meta.ordering.
Regression in 6d4e5feb79f7eabe8a0c7c4b87f25b1a7f87ca0b.
Co-Authored-By: Mariusz Felisiak <felisiak...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:11>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"8289fc55fff879df273cb95fdd1b039447f85783" 8289fc55]:
{{{
#!CommitTicketReference repository=""
revision="8289fc55fff879df273cb95fdd1b039447f85783"
Refs #30449 -- Made RelatedOnlyFieldListFilter respect
ModelAdmin.ordering.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:12>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"c2732e6839fffd96b136607f10af95fe58e0de17" c2732e6]:
{{{
#!CommitTicketReference repository=""
revision="c2732e6839fffd96b136607f10af95fe58e0de17"
[2.2.x] Fixed #30449 -- Fixed
RelatedFieldListFilter/RelatedOnlyFieldListFilter to respect model's
Meta.ordering.
Regression in 6d4e5feb79f7eabe8a0c7c4b87f25b1a7f87ca0b.
Co-Authored-By: Mariusz Felisiak <felisiak...@gmail.com>
Backport of 00035672a460b6eb5442d2837bc783f8af28c6f3 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30449#comment:13>