Multi-sort in admin does not respect initial admin_order_field
|Reported by:||Sebastian Goll||Owned by:||nobody|
|Severity:||Release blocker||Keywords:||multi-sort, admin, ordering|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
The multi-sort addition to the admin change list (introduced in #11868) fails to set the sort indicators for the default ordering in the following case: the model admin's
ordering refers not to a proper field but to the name of a method with
admin_order_field set. That method can either be defined in the model admin or the model itself, it doesn't matter.
The problem is easily fixed by the attached patch. We have to resolve the name that was given in
list_display both when applying the actual ordering, as well as when getting the default ordering in case no explicit
ORDER_VAR has yet been passed to the view.
Since the same functionality is required both within method
get_ordering_field_columns, I moved the shared code to the new method
_get_admin_order_field which simply does what the name indicates.
Change History (12)
comment:1 Changed 5 years ago by
|Patch needs improvement:||unset|
comment:4 follow-up: 6 Changed 5 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Accepted|