From ec2c9c353113bb1db6e32ed3f0b6c28bc06ca2eb Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 14 Jun 2018 14:47:20 -0400 Subject: Refs #29428 -- Fixed admin check crash when using a query expression in ModelAdmin.ordering. --- tests/modeladmin/test_checks.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/modeladmin') 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): -- cgit v1.3