ModelAdmin.ordering validation too strict
|Reported by:||Sebastian Goll||Owned by:||nobody|
|Severity:||Normal||Keywords:||admin, validation, ordering, strict|
|Cc:||Sebastian Goll, k@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
ModelAdmin.ordering checks whether all elements are the names of valid fields on the model. This is too strict as we can also define methods on the model or admin class and set
admin_order_field. In fact, if such columns are used in
list_display they are sortable by clicking on the corresponding column in the change list view.
The attached patch relaxes the admin validation so that the names of such methods are allowed for the default sorting. It also adds several tests to check this relaxed validation.
Change History (6)
comment:1 Changed 5 years ago by
|Patch needs improvement:||unset|