mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Refs #30798 -- Prevented chaining fields from the same related model multiple times in model Meta.ordering.
This commit is contained in:
parent
c2678e4975
commit
c7944628a1
2 changed files with 22 additions and 0 deletions
|
@ -814,6 +814,26 @@ class OtherModelTests(SimpleTestCase):
|
|||
)
|
||||
])
|
||||
|
||||
def test_ordering_pointing_multiple_times_to_model_fields(self):
|
||||
class Parent(models.Model):
|
||||
field1 = models.CharField(max_length=100)
|
||||
field2 = models.CharField(max_length=100)
|
||||
|
||||
class Child(models.Model):
|
||||
parent = models.ForeignKey(Parent, models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
ordering = ('parent__field1__field2',)
|
||||
|
||||
self.assertEqual(Child.check(), [
|
||||
Error(
|
||||
"'ordering' refers to the nonexistent field, related field, "
|
||||
"or lookup 'parent__field1__field2'.",
|
||||
obj=Child,
|
||||
id='models.E015',
|
||||
)
|
||||
])
|
||||
|
||||
def test_ordering_allows_registered_lookups(self):
|
||||
class Model(models.Model):
|
||||
test = models.CharField(max_length=100)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue