from django.db.models.functions import TruncMonth
from django.db.models import Count
Sales.objects
.annotate(month=TruncMonth('created')) # Truncate to month and add to select list
.values('month') # Group By month
.annotate(c=Count('id')) # Select the count of the grouping
.values('month', 'c') # (might be redundant, haven't tested) select month and count
Request.objects.extra({ "month": ExtractMonth('date_creation'),
"year": ExtractYear('date_creation') })
.values('month', 'year')
.annotate(total=Count('month'))
.values('month', 'year', 'total')