mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #29428 -- Fixed admin check crash when using a query expression in ModelAdmin.ordering.
This commit is contained in:
parent
0d8e3e608e
commit
ec2c9c3531
3 changed files with 30 additions and 1 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue