从django Q查询弹出查询?

Yuj*_*ita 4 python django django-q

我正在使用看起来像这样的查询:

    filters = Q(is_default = False)
    # Build the excludes and filters dynamically 
    if cut:
        filters = filters & Q(mailbagstats__num_letters2__gt = int(cut) )
Run Code Online (Sandbox Code Playgroud)

鉴于filters Q查询,我可以查询pop其中一个吗?

我想Q(mailbagstats__num_letters2__gt= int(cut) )从此Q查询中删除查询,以获取新的过滤器.

通常情况下,我使用列表,reduce但这个是通过构造, Q() & Q()所以我不知道如何修改它.

感谢您提供的任何输入!

Cés*_*sar 5

你可以pop:

>>> filter = Q(a=True)
>>> filter = filter & Q(b=True)
>>> filter.children
[('a', True), ('b', True)]
>>> filter.children.pop()
('b', True)
>>> filter.children
[('a', True)]
Run Code Online (Sandbox Code Playgroud)

  • 非常好!谢谢!我将编写一个函数,它接受一个键并遍历列表(`children`也需要递归)并弹出它们! (2认同)