【Python】Django 聚合 Count与Sum用法,注意点

代码示例:

from django.db.models import Sum, Count
#alarm_sum_group_items = models.FILE_PROTECT_ALARM.objects.filter(**condition).filter(device_hash=tmp_dict['device_hash']).values('device_hash').annotate(alarm_sum=Sum('cmn_merge_count'))
#tmp_dict['customer_id'] = customer_id
#tmp_dict['alarm_sum'] = alarm_sum_group_items[]['alarm_sum'] if (len(alarm_sum_group_items)!=) else alarm_sum = models.FILE_PROTECT_ALARM.objects.filter(**condition).filter(device_hash=tmp_dict['device_hash']).aggregate(Sum("cmn_merge_count"))
# {'cmn_merge_count__sum': None}
tmp_dict['alarm_sum'] = alarm_sum['cmn_merge_count__sum'] if (alarm_sum['cmn_merge_count__sum'] is not None) else rule_sum = models.FILE_PROTECT_RULE_UPDATE.objects.filter(customer_id=customer_id).filter(device_hash=tmp_dict['device_hash']).aggregate(Count("id"))
# {'id__count': }
tmp_dict['rule_sum'] = rule_sum['id__count']
上一篇:ASP.NET Core 异常处理与日志记录


下一篇:C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理