• Q函数的使用


    """ Q函数的使用"""
    # 查询username 或者nicjname 都为zhangsan 的用户
    # user_list = WeiboUser.objects.filter(username='zhangsan')
    # user_list2 = WeiboUser.objects.filter(nickname='zhangsan')
    # print(user_list)
    # print(user_list2)

    # name = request.GET.get('name', None)
    # print(name)
    # query = Q(username=name) | Q(nickname=name)
    # user_list = WeiboUser.objects.filter(query)
    # print(user_list)

    # username 按用户名查询
    # username = request.GET.get('username', None)
    # query = Q()
    # if username is not None:
    # query = query & Q(username=username)
    # # nickname 按昵称来查询
    # nickname = request.GET.get('nickname', None)
    # query = Q()
    # if nickname is not None:
    # query = query & Q(nickname=nickname)
    # user_list_q2 = WeiboUser.objects.filter(query)
    # print(user_list_q2)
  • 相关阅读:
    Cyber Security
    Cyber Security
    Cyber Security
    Cyber Security
    Balanced Number HDU
    Round Numbers POJ
    Bomb HDU
    不要62 HDU
    Making the Grade POJ
    You Are the One HDU
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/11475255.html
Copyright © 2020-2023  润新知