对Django查询集完成字典分析找出相对的查询集 demo仅供参考
from django.shortcuts import render, HttpResponse
from rest_framework.views import APIView
class LoginView(APIView):
def post(self, request):
# 获取要登录的信息
username = request.POST.get('username')
password = request.POST.get('password')
if username == 'xiaowang':
fla = User.objects.values('u_id')
# print(type(fla))
# flg = (type(str(fla)))
# flg = fla[:-1]
# print(flg)
for item in fla:
print(item,'-----')
# print(max(item.values()))
print(max(item.values(), key=lambda x: x[1]))
obj = max(item.values(), key=lambda x: x[1])
User.objects.create(username=username,password=password,u_id=int(obj) +1)
return HttpResponse('ok')