Django

2018-10-12 Django 按日期/月份分组

2018-10-12  本文已影响0人  多吃水果少吃肉

转载自:https://www.aliyun.com/jiaocheng/520296.html

Entry.objects.extra(select={'month':'extract(monthfrompub_date)'}).values('month').annotate(dcount=Count('pub_date'))

#Entry.objects.extra(select={'month':'extract(monthfrompub_date)'}).values('month')

#Entry.objects.annotate(month=ExtractMon
*   Entry.objects.extra(select={'month': 'extract( month from pub_date )'}).values('month').annotate(dcount=Count('pub_date')) 
   
 #  <queryset [{'month':="" 8,="" 'dcount':="" 3},="" {'month':="" 7,="" 2}]="">Entry.objects.extra(select={'month': 'extract( month from pub_date )'}).values('month') 
    
#  <queryset [{'month':="" 8},="" {'month':="" 7},="" 7}]="" data-spm-anchor-id="5176.100033.1.i1.1512291alVFQuH">

Entry.objects.annotate(month=ExtractMonth('pub_date')).values('month').annotate(nums=Count('pub_date')) 
    
# <queryset [{'month':="" 8,="" 'nums':="" 3},="" {'month':="" 7,="" 2}]="">两种方式实现按月分统计数量

按年和按天同理

参考链接
以上是django 日期 分组的内容,更多 分组 日期 Django 的内容,请您使用右上方搜索功能获取相关信息。

上一篇 下一篇

猜你喜欢

热点阅读