#30981: Admin changelist crashes when using query expression in the ModelAdmin's
admin_order_field
-----------------------------------------+------------------------
               Reporter:  Petr DlouhĂ˝    |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  contrib.admin  |        Version:  2.2
               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              |
-----------------------------------------+------------------------
 When I use `admin_order_field` with F() expression or any other type of
 expression that doesn't have `as_sql` such as:

 {{{
 class UserProfileAdmin(admin.ModelAdmin):
     def get_sum_amount(self, obj):
           return obj.sum_amount
       get_sum_amount.admin_order_field = F('sum_amount')

 }}}

 I got the following crash:


 {{{
 Traceback (most recent call last):
   File "/home/petr/.local/share/virtualenvs/aklub_project-
 HrPEZ5ak/lib/python3.6/site-packages/django/template/base.py", line 835,
 in _resolve_lookup
     return self.get_fields()
   File "/home/petr/.local/share/virtualenvs/aklub_project-
 HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py",
 line 81, in __init__
     self.queryset = self.get_queryset(request)
   File "/home/petr/.local/share/virtualenvs/aklub_project-
 HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py",
 line 435, in get_queryset
     ordering = self.get_ordering(request, qs)
   File "/home/petr/.local/share/virtualenvs/aklub_project-
 HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py",
 line 296, in get_ordering
     elif order_field.startswith('-') and pfx == '-':
 AttributeError: 'F' object has no attribute 'startswith'
 }}}

 This is similar issue like https://code.djangoproject.com/ticket/28958 but
 wasn't fixed by the patch.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30981>
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.2d7d498d73863a40ad5bc8aca6cc74b2%40djangoproject.com.

Reply via email to