Django filter()

from functools import reduce

lst = [Q(question_text__contains='you'), Q(question_text__contains='who')]

# OR
>>> Question.objects.filter(reduce(operator.or_, lst))
[<Question: what are you doing>, <Question: what is wrong with you>, <Question: who are you>, <Question: who am i>]

# AND
>>> Question.objects.filter(reduce(operator.and_, lst))
[<Question: who are you>]


>>> from functools import reduce
>>> reduce(lambda x, y: x + y, [1,2,3,4,5,6,7,8])
36
发布了38 篇原创文章 · 获赞 2 · 访问量 1102
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览