Commit 2100bcef authored by Daniel Pyrathon's avatar Daniel Pyrathon Committed by Tim Graham
Browse files

[1.7.x] Added a unit test to ensure models cannot be ordered by a M2M field.

Backport of 865bc717 from master
parent 9918b764
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -375,6 +375,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: