From 865bc7178364145f901c5ac5a5b8eb722cc0a646 Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Tue, 8 Jul 2014 11:24:08 +0200 Subject: [PATCH] Added a unit test to ensure models cannot be ordered by a M2M field. --- tests/invalid_models_tests/test_models.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 6bce3f9a26..3bfccdb2a9 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -540,6 +540,27 @@ class OtherModelTests(IsolatedModelsTestCase): ] 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: