summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnssi Kääriäinen <anssi.kaariainen@thl.fi>2016-01-20 11:05:48 +0200
committerTim Graham <timograham@gmail.com>2016-01-20 19:16:18 -0500
commit05e8fa83c378c882ab4d4a1012ce954a9dced6de (patch)
tree4e610010630b0ae442188e8d553cd94c130edf10 /tests
parent076d4591108764695582ab272fdb7f348b4c161c (diff)
[1.9.x] Fixed #26092 -- Fixed QuerySet.order_by() regression with an M2M through model.
Backport of ee596888e1149864e7828f5cf63c0eda395744c3 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/m2m_through/models.py1
-rw-r--r--tests/m2m_through/tests.py14
2 files changed, 15 insertions, 0 deletions
diff --git a/tests/m2m_through/models.py b/tests/m2m_through/models.py
index c25303f6f5..dab3be5164 100644
--- a/tests/m2m_through/models.py
+++ b/tests/m2m_through/models.py
@@ -65,6 +65,7 @@ class CustomMembership(models.Model):
class Meta:
db_table = "test_table"
+ ordering = ["date_joined"]
class TestNoDefaultsOrNulls(models.Model):
diff --git a/tests/m2m_through/tests.py b/tests/m2m_through/tests.py
index 0d6609a6cd..5f5d78ea28 100644
--- a/tests/m2m_through/tests.py
+++ b/tests/m2m_through/tests.py
@@ -197,6 +197,20 @@ class M2mThroughTests(TestCase):
attrgetter("name")
)
+ def test_order_by_relational_field_through_model(self):
+ CustomMembership.objects.create(person=self.jim, group=self.rock)
+ CustomMembership.objects.create(person=self.bob, group=self.rock)
+ CustomMembership.objects.create(person=self.jane, group=self.roll)
+ CustomMembership.objects.create(person=self.jim, group=self.roll)
+ self.assertQuerysetEqual(
+ self.rock.custom_members.order_by('custom_person_related_name'),
+ [self.jim, self.bob], lambda x: x
+ )
+ self.assertQuerysetEqual(
+ self.roll.custom_members.order_by('custom_person_related_name'),
+ [self.jane, self.jim], lambda x: x
+ )
+
def test_query_first_model_by_intermediate_model_attribute(self):
Membership.objects.create(
person=self.jane, group=self.roll,