summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonatas CD <jonatas.cd@gmail.com>2016-11-15 12:54:45 +0100
committerTim Graham <timograham@gmail.com>2016-11-17 12:39:56 -0500
commit02ac92888e6df058cc61ca72e24e499769336d32 (patch)
tree88afd5a56425c946103237abc3c8d4e972d1b086 /tests
parentfe8b55699a780b78a0242308b4ed7b939043b568 (diff)
[1.10.x] Fixed #27482 -- Doc'd an example of Case() in QuerySet.filter().
Backport of b28c6ca7631e13ea29490bf51a367ab10198c74c from master
Diffstat (limited to 'tests')
-rw-r--r--tests/expressions_case/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py
index 30e8a704ae..385cb88215 100644
--- a/tests/expressions_case/tests.py
+++ b/tests/expressions_case/tests.py
@@ -1279,3 +1279,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')
+ )