django 按天统计发布单数量
from datetime import datetime, timedelta
from django.http import JsonResponse
from deploy.models import DeployPool
from django.db.models import Count
def get_a_month_deploy(request):
return_list = []
now = datetime.now()
a_month = now - timedelta(days=50)
select = {'day': 'date(add_date)'}
a_month_deploy = DeployPool.objects. \
filter(add_date__range=(a_month, now)). \
extra(select=select).values('day').distinct().order_by("day").annotate(number=Count('add_date'))
for item in a_month_deploy:
item_dict = {}
item_key = item['day'].strftime('%m-%d')
item_dict[item_key] = item['number']
return_list.append(item_dict)
return JsonResponse(return_list, safe=False)
本文来自博客园,作者:super_ip,转载请注明原文链接:https://www.cnblogs.com/superip/p/17320919.html