1. Trunc
# 获取每个月 count总数
from django.db.models import Sum
from django.db.models.functions import Trunc
models.NafpComplete.objects.filter().annotate(month=Trunc('point_time', 'month')).values('month').annotate(count=Sum('count')).values('month', 'count')
# <QuerySet [{'month': datetime.datetime(2022, 1, 1, 0, 0), 'count': 7}, {'month': datetime.datetime(2022, 4, 1, 0, 0), 'count': 3}, {'month': datetime.datetime(2022, 3, 1, 0, 0), 'count': 3}]>
标签:count,Python,Sum,month,annotate,models,日期,orm,Trunc
From: https://www.cnblogs.com/jessecheng/p/17370579.html