diff options
author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-10-11 00:12:10 +0300 |
---|---|---|
committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-11-07 14:29:50 +0200 |
commit | b1b04df06522b092a9b4768d2d61c52956e00eca (patch) | |
tree | 8187a7830e3bcaf5e7cfb354230dcdd39b19e9b3 /tests/distinct_on_fields | |
parent | ccbba98131ace3beb43790c65e8f4eee94e9631c (diff) | |
download | django-b1b04df06522b092a9b4768d2d61c52956e00eca.tar.gz |
Fixed #20600 -- ordered distinct(*fields) in subqueries
Diffstat (limited to 'tests/distinct_on_fields')
-rw-r--r-- | tests/distinct_on_fields/tests.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/distinct_on_fields/tests.py b/tests/distinct_on_fields/tests.py index 9dedd98f81..33ddf80ff4 100644 --- a/tests/distinct_on_fields/tests.py +++ b/tests/distinct_on_fields/tests.py @@ -16,13 +16,13 @@ class DistinctOnTests(TestCase): Tag.objects.create(name='t4', parent=t3) Tag.objects.create(name='t5', parent=t3) - p1_o1 = Staff.objects.create(id=1, name="p1", organisation="o1") - p2_o1 = Staff.objects.create(id=2, name="p2", organisation="o1") - p3_o1 = Staff.objects.create(id=3, name="p3", organisation="o1") - Staff.objects.create(id=4, name="p1", organisation="o2") - p1_o1.coworkers.add(p2_o1, p3_o1) - StaffTag.objects.create(staff=p1_o1, tag=t1) - StaffTag.objects.create(staff=p1_o1, tag=t1) + self.p1_o1 = Staff.objects.create(id=1, name="p1", organisation="o1") + self.p2_o1 = Staff.objects.create(id=2, name="p2", organisation="o1") + self.p3_o1 = Staff.objects.create(id=3, name="p3", organisation="o1") + self.p1_o2 = Staff.objects.create(id=4, name="p1", organisation="o2") + self.p1_o1.coworkers.add(self.p2_o1, self.p3_o1) + StaffTag.objects.create(staff=self.p1_o1, tag=t1) + StaffTag.objects.create(staff=self.p1_o1, tag=t1) celeb1 = Celebrity.objects.create(name="c1") celeb2 = Celebrity.objects.create(name="c2") @@ -114,3 +114,17 @@ class DistinctOnTests(TestCase): # distinct + aggregate not allowed with self.assertRaises(NotImplementedError): Celebrity.objects.distinct('id').aggregate(Max('id')) + + def test_distinct_on_in_ordered_subquery(self): + qs = Staff.objects.distinct('name').order_by('name', 'id') + qs = Staff.objects.filter(pk__in=qs).order_by('name') + self.assertQuerysetEqual( + qs, [self.p1_o1, self.p2_o1, self.p3_o1], + lambda x: x + ) + qs = Staff.objects.distinct('name').order_by('name', '-id') + qs = Staff.objects.filter(pk__in=qs).order_by('name') + self.assertQuerysetEqual( + qs, [self.p1_o2, self.p2_o1, self.p3_o1], + lambda x: x + ) |