#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.

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.6e6d198536d6857ca5f3bd25f120957a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to