首页 > 代码库 > 【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】如何按天 小时等查询统计?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。