Skip to content

Commit

Permalink
Added a unit test to ensure models cannot be ordered by a M2M field.
Browse files Browse the repository at this point in the history
  • Loading branch information
PirosB3 authored and timgraham committed Jul 8, 2014
1 parent 9f18b6b commit 865bc71
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/invalid_models_tests/test_models.py
Expand Up @@ -540,6 +540,27 @@ class Meta:
]
self.assertEqual(errors, expected)

def test_non_valid(self):
class RelationModel(models.Model):
pass

class Model(models.Model):
relation = models.ManyToManyField(RelationModel)

class Meta:
ordering = ['relation']

errors = Model.check()
expected = [
Error(
"'ordering' refers to the non-existent field 'relation'.",
hint=None,
obj=Model,
id='models.E015',
),
]
self.assertEqual(errors, expected)

def test_ordering_pointing_to_missing_field(self):
class Model(models.Model):
class Meta:
Expand Down

0 comments on commit 865bc71

Please sign in to comment.