I'm trying to get number of records per month, but Django does not return correctly when there is "ordering" in class Meta Model.
I have the Abc model, with 4 records made this month, look what happens (Django 1.10, PostgreSQL):
class Abc(Base):
class Meta:
ordering = ['-date_pub']
>>> Abc.objects.annotate(month=TruncMonth('created_at')).values('month').annotate(total=Count('id')).values('total')
<QuerySet [{'total': 1}, {'total': 1}, {'total': 1}, {'total': 1}]>
Without "ordering"
>>> Abc.objects.annotate(month=TruncMonth('created_at')).values('month').annotate(total=Count('id')).values('total')
<QuerySet [{'total': 4}]>
Why this happens? Is it a bug?