#31975: admin_order_field in ModelAdmin doesn't support sorting on multiple
columns
-----------------------------------------+------------------------
Reporter: Petr DlouhĂ˝ | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
If I try to assign list to `admin_order_field` to sort on multiple fields
(like `Model.Meta.ordering` does) like this:
{{{
@admin.register(Invoice)
class InvoiceAdmin(ModelAdmin):
def get_full_number(self, invoice):
return invoice.full_number
get_full_number.admin_order_field = ['issued__year', 'issued__month',
'-number']
}}}
I got following error:
{{{
File "/home/petr/.local/share/virtualenvs/blenderhub_server-
eFlwzMqz/lib/python3.7/site-packages/django/contrib/admin/options.py",
line 1693, in changelist_view
cl = self.get_changelist_instance(request)
File "/home/petr/.local/share/virtualenvs/blenderhub_server-
eFlwzMqz/lib/python3.7/site-packages/django/contrib/admin/options.py",
line 748, in get_changelist_instance
sortable_by,
File "/home/petr/.local/share/virtualenvs/blenderhub_server-
eFlwzMqz/lib/python3.7/site-packages/django/contrib/admin/views/main.py",
line 99, in __init__
self.queryset = self.get_queryset(request)
File "/home/petr/.local/share/virtualenvs/blenderhub_server-
eFlwzMqz/lib/python3.7/site-packages/django/contrib/admin/views/main.py",
line 479, in get_queryset
ordering = self.get_ordering(request, qs)
File "/home/petr/.local/share/virtualenvs/blenderhub_server-
eFlwzMqz/lib/python3.7/site-packages/django/contrib/admin/views/main.py",
line 328, in get_ordering
elif order_field.startswith('-') and pfx == '-':
AttributeError: 'list' object has no attribute 'startswith'
}}}
This is similar to https://code.djangoproject.com/ticket/30981 which has
been fixed, but sorting on multiple fields is still hard to achieve.
--
Ticket URL: <https://code.djangoproject.com/ticket/31975>
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/053.8fd2a8a5fa6a1ab933fb955ad77ae7a5%40djangoproject.com.