mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Fixed #27849 -- Added filtering support to aggregates.
This commit is contained in:
parent
489421b015
commit
b78d100fa6
13 changed files with 290 additions and 55 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue