Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django orm group by month and year

print([v for v in
       Request.objects.annotate(month=ExtractMonth('date_creation'),
                                year=ExtractYear('date_creation'),)
                      .order_by()
                      .values('month', 'year')
                      .annotate(total=Count('*'))
                      .values('month', 'year', 'total')
       ])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #django #orm #group #month #year
ADD COMMENT
Topic
Name
2+1 =