diff options
| author | Josh Smeaton <josh.smeaton@gmail.com> | 2015-03-05 17:10:48 +1100 |
|---|---|---|
| committer | Josh Smeaton <josh.smeaton@gmail.com> | 2015-03-06 13:30:02 +1100 |
| commit | ceaf31adfff3801f1092a215f73704e15a70e90c (patch) | |
| tree | 572e288a9b778956aed01f6fb570285b16937597 /tests/annotations | |
| parent | 82f7bee1d56e1bf8ae041c6cdeb7374ea6b844de (diff) | |
Fixed #24420 -- Allowed ordering by case expressions
Diffstat (limited to 'tests/annotations')
| -rw-r--r-- | tests/annotations/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 2fc42147eb..b5159b6120 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -280,6 +280,24 @@ class NonAggregateAnnotationTestCase(TestCase): book = Book.objects.annotate(no_value=Value(None, output_field=IntegerField())).first() self.assertIsNone(book.no_value) + def test_order_by_annotation(self): + authors = Author.objects.annotate(other_age=F('age')).order_by('other_age') + self.assertQuerysetEqual( + authors, [ + 25, 29, 29, 34, 35, 37, 45, 46, 57, + ], + lambda a: a.other_age + ) + + def test_order_by_aggregate(self): + authors = Author.objects.values('age').annotate(age_count=Count('age')).order_by('age_count', 'age') + self.assertQuerysetEqual( + authors, [ + (25, 1), (34, 1), (35, 1), (37, 1), (45, 1), (46, 1), (57, 1), (29, 2), + ], + lambda a: (a['age'], a['age_count']) + ) + def test_column_field_ordering(self): """ Test that columns are aligned in the correct order for |
