有谁知道我如何得到Django Filter构建一个OR语句?我不知道如果我要使用默认的Q对象或没有,我想我需要某种类型或管道,但这似乎并不正确:Django过滤器循环或
我想这是:
SELECT * FROM table WHERE mfr_method = 1 OR mfr_method = 2 OR mfr_method = 3
编辑:这是什么工作
filter_mfr_method = request.GET.getlist('filter_mfr_method')
list = []
for m in filter_mfr_method:
list.append(Q(mfr_method = m))
designs = designs.filter(reduce(operator.or_, list))
我永远不会猜到的人。我一直在这一行上得到一个'TypeError,Exception Value 1'filter_params = reduce(operator.or_,filter_mfr_method,Q())' - 这与ID的im从'getlist'传递 - 你知道吗为什么这是,我现在查找这个减少功能 – JREAM
'getlist'可能是问题。我没有真正考虑它的作用而复制它。你可能需要在request.GET.getlist('filter_mfr_method')]中为'filter_mfr_method = [{'mfr_method':m}'做一些事情'' – Ngenator
谢谢,我把我最新的最终结果发布在主要消息中:) – JREAM