diff options
| author | Tim Graham <timograham@gmail.com> | 2018-06-14 14:47:20 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-06-14 21:04:43 -0400 |
| commit | ec2c9c353113bb1db6e32ed3f0b6c28bc06ca2eb (patch) | |
| tree | bc14f43bc225954b463ef0ef50fdec1a8253d697 /django | |
| parent | 0d8e3e608ee9aab5076d497664aa97e0a29e523e (diff) | |
Refs #29428 -- Fixed admin check crash when using a query expression in ModelAdmin.ordering.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/checks.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index e0f3a21550..cf5b312369 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -10,6 +10,7 @@ from django.core import checks from django.core.exceptions import FieldDoesNotExist from django.db import models from django.db.models.constants import LOOKUP_SEP +from django.db.models.expressions import Combinable, F, OrderBy from django.forms.models import ( BaseModelForm, BaseModelFormSet, _get_foreign_key, ) @@ -489,7 +490,13 @@ class BaseModelAdminChecks: def _check_ordering_item(self, obj, model, field_name, label): """ Check that `ordering` refers to existing fields. """ - + if isinstance(field_name, (Combinable, OrderBy)): + if not isinstance(field_name, OrderBy): + field_name = field_name.asc() + if isinstance(field_name.expression, F): + field_name = field_name.expression.name + else: + return [] if field_name == '?' and len(obj.ordering) != 1: return [ checks.Error( |
