﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30981	Admin changelist crashes when using F() and OrderBy() expressions in the ModelAdmin's admin_order_field.	Petr Dlouhý	Hasan Ramezani	"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."	Bug	closed	contrib.admin	dev	Normal	fixed			Accepted	1	0	0	0	0	0
