#35747: Admin change list doesn't redirect to default ordering when the last
ordering field is removed from sorting
-------------------------------------+-------------------------------------
Reporter: ldeluigi | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: admin change list | Triage Stage:
ordering sorting sortremove | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by ldeluigi):
* resolution: invalid =>
* status: closed => new
Comment:
> To me, the change list is ordered with the default ordering.
It's not: I've defined default ordering in my model's Meta class, like
this:
{{{
...
class Meta:
....
ordering = [
models.Case(
models.When(status='D', then=models.Value(0)),
models.When(status='N', then=models.Value(1)),
...,
default=models.Value(10),
),
'-created'
]
}}}
If I navigate to the admin change list page, without query parameters in
the URL, I see that the ordering is applied to the results.
Instead, if I navigate to `.../?o=` I see a totally different ordering
being applied.
By enabling the debugger, I can see that the latter sorts by id descending
and doesn't honor the ordering of the model's meta class. This is caused
by the behaviour of `_get_deterministic_ordering` on the ChangeList class,
which receives an empty list because the `get_ordering` method overwrites
the default ordering with an empty list whenever the ORDER_VAR is passed
in params.
Reference:
https://github.com/django/django/blob/cdbd31960e0cf41063b3efac97292ee0ccc262bb/django/contrib/admin/views/main.py#L385
--
Ticket URL: <https://code.djangoproject.com/ticket/35747#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070191d76676f9-b2f38e15-c0b4-4bba-9c91-47b03b9c99cc-000000%40eu-central-1.amazonses.com.