I tried multiple approach, but could not come to solution.
I have event model like this:
class Event(models.Model):
start_date = models.DateTimeField()
end_date = models.DateTimeField()
location = models.CharField(max_length=250)
I want to group events by year and then months:
2013
Jan
- Event 1
- Event 2
Feb
- Event 1
- Event 2
2014
Jan
- Event 1
- Event 2
I am only taking start_date while doing sorting.
At last I was thinking this would work, but it doesn't:
Event.objects.values_list('start_date__year').annotate(dcount=Count('start_date__year'))