美文网首页Django
2018-10-12 Django 按日期/月份分组

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

作者: 多吃水果少吃肉 | 来源:发表于2018-10-12 14:53 被阅读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 的内容,请您使用右上方搜索功能获取相关信息。

相关文章

网友评论

    本文标题:2018-10-12 Django 按日期/月份分组

    本文链接:https://www.haomeiwen.com/subject/xnhgaftx.html