mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #27849 -- Added filtering support to aggregates.
This commit is contained in:
@@ -1253,6 +1253,15 @@ class CaseDocumentationExamples(TestCase):
|
||||
account_type=Client.PLATINUM,
|
||||
registered_on=date.today(),
|
||||
)
|
||||
self.assertEqual(
|
||||
Client.objects.aggregate(
|
||||
regular=models.Count('pk', filter=Q(account_type=Client.REGULAR)),
|
||||
gold=models.Count('pk', filter=Q(account_type=Client.GOLD)),
|
||||
platinum=models.Count('pk', filter=Q(account_type=Client.PLATINUM)),
|
||||
),
|
||||
{'regular': 2, 'gold': 1, 'platinum': 3}
|
||||
)
|
||||
# This was the example before the filter argument was added.
|
||||
self.assertEqual(
|
||||
Client.objects.aggregate(
|
||||
regular=models.Sum(Case(
|
||||
|
||||
Reference in New Issue
Block a user