Browse files

Added a unit test to ensure models cannot be ordered by a M2M field.

  • Loading branch information...
1 parent 9f18b6b commit 865bc7178364145f901c5ac5a5b8eb722cc0a646 @PirosB3 PirosB3 committed with timgraham Jul 8, 2014
Showing with 21 additions and 0 deletions.
  1. +21 −0 tests/invalid_models_tests/test_models.py
View
21 tests/invalid_models_tests/test_models.py
@@ -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:

0 comments on commit 865bc71

Please sign in to comment.