From b28c6ca7631e13ea29490bf51a367ab10198c74c Mon Sep 17 00:00:00 2001 From: Jonatas CD Date: Tue, 15 Nov 2016 12:54:45 +0100 Subject: Fixed #27482 -- Doc'd an example of Case() in QuerySet.filter(). --- tests/expressions_case/tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py index c3b754fcae..91806c2764 100644 --- a/tests/expressions_case/tests.py +++ b/tests/expressions_case/tests.py @@ -1289,3 +1289,17 @@ class CaseDocumentationExamples(TestCase): ), {'regular': 2, 'gold': 1, 'platinum': 3} ) + + def test_filter_example(self): + a_month_ago = date.today() - timedelta(days=30) + a_year_ago = date.today() - timedelta(days=365) + self.assertQuerysetEqual( + Client.objects.filter( + registered_on__lte=Case( + When(account_type=Client.GOLD, then=a_month_ago), + When(account_type=Client.PLATINUM, then=a_year_ago), + ), + ), + [('Jack Black', 'P')], + transform=attrgetter('name', 'account_type') + ) -- cgit v1.3