{{{
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.
* status: new => assigned
* owner: nobody => Andreas Pelme
--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8026 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:3>
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>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/27810#comment:5>
* 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>