Aggregation doesnt work with Models, ordered by Meta subclass
Hello,
Using aggregation methods with models, that have set 'ordering' in Meta subclass fails:
class M1 (models.Model)
date = models.DateField()
smth = models.IntegerField()
class Meta:
ordeing = 'smth'
count_by_day_qs = M1.objects.values('date').annotate(c=models.Count('id')).values('date', 'c')
#Executes following query:
SELECT "m1"."date", COUNT("m1"."id") AS "c" FROM "m1" GROUP BY "m1"."date", "m1"."smth"
Change History
(4)
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Owner: |
changed from nobody to Dede Dian
|
Status: |
new → assigned
|
Resolution: |
→ invalid
|
Status: |
assigned → closed
|
This is documented as a caveat of performing aggregation against a model with a defined
Meta.ordering
https://docs.djangoproject.com/en/3.1/topics/db/aggregation/#interaction-with-default-ordering-or-order-by
Please TicketClosingReasons/UseSupportChannels before filling a ticket in the future.