So my model is like this:
class Blog(models.Model):
title = models.CharField(max_length=100)
publication_date = models.DateField()
And now I want to get the count of the blog posts by each month. The raw sql would look like:
SELECT COUNT (*), EXTRACT(MONTH FROM publication_date) AS month FROM blog GROUP BY month;
One solution I found is here, it suggests that getting a date list first then loop through it using filter
for each iteration. I do not like it, I am looking for a way to get the result without using loop.