码迷,mamicode.com
首页 > 其他好文 > 详细

【Django】如何按天 小时等查询统计?

时间:2016-10-15 19:14:44      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

代码:

from django.db import connection
        from django.db.models import Sum,Count
        #alarm_sum_group_items = models.FILE_PROTECT_ALARM.objects.filter(**condition).values(customer_id).annotate(alarm_sum=Sum(cmn_merge_count))
        select = {day: connection.ops.date_trunc_sql(day, cmn_alert_time)}
        alarm_sum_group_items = models.FILE_PROTECT_ALARM.objects.filter(**condition).extra(select=select).values(day).annotate(sum=Sum(cmn_merge_count))
        #serializer = serializers.FILE_PROTECT_ALARM_Serializer(file_protect_alarm_list, many=True)
        #data = {}
        #data[items] = serializer.data
        ‘‘‘for item in data[items]:
            item[svc_profile_list] = json.loads(item[svc_profile_list])
            #item[info] = json.loads(item[info])‘‘‘
        #data[total] = total
        for item in alarm_sum_group_items:
            item[day] = time.mktime(item[day].timetuple())
        return APIResponse(status=status_code.success, data=alarm_sum_group_items)

 

参考资料:

http://www.360doc.com/content/14/0430/17/16044571_373542312.shtml

http://blog.csdn.net/shanliangliuxing/article/details/7927899

http://www.thinksaas.cn/ask/question/23626/

https://segmentfault.com/q/1010000003499386

http://blog.csdn.net/pipisorry/article/details/47396311

 

【Django】如何按天 小时等查询统计?

标签:

原文地址:http://www.cnblogs.com/junneyang/p/5965058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!