summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-06-14 14:47:20 -0400
committerTim Graham <timograham@gmail.com>2018-06-15 10:00:38 -0400
commit531a152c657920db5221782a91dc6a0a06077085 (patch)
tree5b14a6b5a483afaf06d467d792856a7bf37fad00 /tests
parenta041161bde7fdcd3b101bc3c7717f3fa15c63542 (diff)
[2.1.x] Refs #29428 -- Fixed admin check crash when using a query expression in ModelAdmin.ordering.
Backport of ec2c9c353113bb1db6e32ed3f0b6c28bc06ca2eb from master
Diffstat (limited to 'tests')
-rw-r--r--tests/modeladmin/test_checks.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py
index f76b78078a..5a0433deb4 100644
--- a/tests/modeladmin/test_checks.py
+++ b/tests/modeladmin/test_checks.py
@@ -3,6 +3,8 @@ from django.contrib.admin import BooleanFieldListFilter, SimpleListFilter
from django.contrib.admin.options import VERTICAL, ModelAdmin, TabularInline
from django.contrib.admin.sites import AdminSite
from django.core.checks import Error
+from django.db.models import F
+from django.db.models.functions import Upper
from django.forms.models import BaseModelFormSet
from django.test import SimpleTestCase
@@ -829,6 +831,23 @@ class OrderingCheckTests(CheckTestCase):
self.assertIsValid(TestModelAdmin, ValidationTestModel)
+ def test_invalid_expression(self):
+ class TestModelAdmin(ModelAdmin):
+ ordering = (F('nonexistent'), )
+
+ self.assertIsInvalid(
+ TestModelAdmin, ValidationTestModel,
+ "The value of 'ordering[0]' refers to 'nonexistent', which is not "
+ "an attribute of 'modeladmin.ValidationTestModel'.",
+ 'admin.E033'
+ )
+
+ def test_valid_expression(self):
+ class TestModelAdmin(ModelAdmin):
+ ordering = (Upper('name'), Upper('band__name').desc())
+
+ self.assertIsValid(TestModelAdmin, ValidationTestModel)
+
class ListSelectRelatedCheckTests(CheckTestCase):