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
标签:Count,05,models,按年,month,annotate,import,年月日,select 来源: https://www.cnblogs.com/chijintao/p/14843980.html