• 对字典中找出最大的值


    对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')
    
  • 相关阅读:
    __get__,__set__,__delete__
    __getattr__,__setattr__,__delattr__
    json ,pickle
    @property
    类的封装
    super
    继承顺序
    派生组合示例
    类的派生,组合
    class 属性查找
  • 原文地址:https://www.cnblogs.com/wangxiaosai/p/15569766.html
Copyright © 2020-2023  润新知