[Django] #27810: ModelAdmin list_display callable does not support query expressions in admin_order_field

6 views
Skip to first unread message

Django

unread,
Feb 6, 2017, 9:10:04 AM2/6/17
to django-...@googlegroups.com
#27810: ModelAdmin list_display callable does not support query expressions in
admin_order_field
-----------------------------------------+------------------------
Reporter: Andreas Pelme | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
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 |
-----------------------------------------+------------------------
Query expressions cannot currently be used with admin_order_field in a
callable on list_display. The code expects a string and crashes when an
query expression object is passed instead. This example shows the problem:

{{{
def full_name(obj):
return f'{obj.first_name} {obj.last_name}'
my_callable.admin_order_field = Concat(F('first_name'), F('last_name'))
}}}

... which leads to a crash like this:

{{{
...
self.queryset = self.get_queryset(request)
File "/Users/andreas/code/django/django/contrib/admin/views/main.py",
line 346, in get_queryset
ordering = self.get_ordering(request, qs)
File "/Users/andreas/code/django/django/contrib/admin/views/main.py",
line 260, in get_ordering
if order_field.startswith('-') and pfx == "-":
AttributeError: 'CombinedExpression' object has no attribute 'startswith'
}}}

It would make sense to be able to make use of all the nice stuff that has
gone into query expression from the admin in this case! :)

--
Ticket URL: <https://code.djangoproject.com/ticket/27810>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 6, 2017, 9:10:20 AM2/6/17
to django-...@googlegroups.com
#27810: ModelAdmin list_display callable does not support query expressions in
admin_order_field
-------------------------------+-----------------------------------------
Reporter: Andreas Pelme | Owner: Andreas Pelme
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by Andreas Pelme):

* status: new => assigned
* owner: nobody => Andreas Pelme


--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:1>

Django

unread,
Feb 6, 2017, 12:25:21 PM2/6/17
to django-...@googlegroups.com
#27810: Add query expression support for ModelAdmin list_display's

admin_order_field
-------------------------------+-----------------------------------------
Reporter: Andreas Pelme | Owner: Andreas Pelme
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:2>

Django

unread,
Feb 6, 2017, 12:33:06 PM2/6/17
to django-...@googlegroups.com
#27810: Add query expression support for ModelAdmin list_display's
admin_order_field
-------------------------------+-----------------------------------------
Reporter: Andreas Pelme | Owner: Andreas Pelme
Type: New feature | Status: assigned
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/8026 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:3>

Django

unread,
Oct 6, 2017, 4:24:52 PM10/6/17
to django-...@googlegroups.com
#27810: Add query expression support for ModelAdmin list_display's
admin_order_field
-------------------------------+-----------------------------------------
Reporter: Andreas Pelme | Owner: Andreas Pelme
Type: New feature | Status: assigned
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------

Comment (by simonwiles):

any chance of this getting committed? it would be very useful to have...

(specific use-case that drove me here: sorting in admin on a DateField
that has NULLs...)

--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:4>

Django

unread,
Feb 15, 2018, 10:12:20 AM2/15/18
to django-...@googlegroups.com
#27810: Add query expression support for ModelAdmin list_display's
admin_order_field
-------------------------------------+-------------------------------------

Reporter: Andreas Pelme | Owner: Andreas
| Pelme
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:5>

Django

unread,
Feb 15, 2018, 9:01:04 PM2/15/18
to django-...@googlegroups.com
#27810: Add query expression support for ModelAdmin list_display's
admin_order_field
-------------------------------------+-------------------------------------
Reporter: Andreas Pelme | Owner: Andreas
| Pelme
Type: New feature | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"e307ff29d28737d5a764ce2fa7db010231d6fc8e" e307ff29]:
{{{
#!CommitTicketReference repository=""
revision="e307ff29d28737d5a764ce2fa7db010231d6fc8e"
Fixed #27810 -- Allowed query expressions in admin_order_field.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:6>

Reply all
Reply to author
Forward
0 new messages