首页 > 代码库 > 【Django】如何按天 小时等查询统计?

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

代码:

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=http://www.mamicode.com/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】如何按天 小时等查询统计?