diff options
| author | Tim Graham <timograham@gmail.com> | 2018-06-14 14:47:20 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-06-15 10:12:44 -0400 |
| commit | 83986af95dc432e54ba71f0c5c13f5e5c02c92e5 (patch) | |
| tree | 143140e5bf00270c70ce28a11f414429a5aff147 /tests/modeladmin | |
| parent | 4bccfac36fa765494cbaa03f79453f97a92ec921 (diff) | |
[2.0.x] Refs #29428 -- Fixed admin check crash when using a query expression in ModelAdmin.ordering.
Backport of ec2c9c353113bb1db6e32ed3f0b6c28bc06ca2eb from master
Diffstat (limited to 'tests/modeladmin')
| -rw-r--r-- | tests/modeladmin/test_checks.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py index 5559a8fe3c..b6a80a29a5 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 @@ -815,6 +817,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): |
