05:将年月日按年月分类

from django.db.models.functions import TruncMonth

from django.db.models import Count

 

Sales.objects

    .annotate(month=TruncMonth('timestamp'))  # 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 

 

上一篇:Matplotlib库 标注点函数annotate()


下一篇:IDEA 查看每行的最后一次提交历史