Python list to bitwise operations

前端 未结 1 503
你的背包
你的背包 2021-01-02 04:43

Is there a way to take a list of django query expresses (e.g. Q(first_name=\"Jordan\"), where Q is django.db.models.Q) and bitwise OR

相关标签:
1条回答
  • 2021-01-02 05:33

    You probably want

    import operator 
    from functools import reduce    # Python 3
    search_params = reduce(operator.or_, search_params, Q())
    

    This will place a bit-wise or (|) between all the items in search_params, starting with an empty condition Q().

    0 讨论(0)
提交回复
热议问题