【发布时间】:2018-04-24 12:03:30
【问题描述】:
我有查询集列表(全部用于同一模型):
results = Entry.objects.all()
result_elms = []
if city_list:
for city in city_list:
result_elms.append(results.filter(address__city__icontains=city))
if county_list:
for county in county_list:
results_elms.append(results.filter(address__county__icontains=county))
#other filters here, daynamically created
#how can I combine all results_elms (querysets) into one?
我知道我可以使用| 运算符来组合来自同一模型的查询集。
但是如何将它应用于result_elms 列表中的所有元素?
【问题讨论】:
-
您的问题中没有足够的细节来给出答案。您应该为其他人提供足够的信息来重现问题,并清楚地描述您正在寻找的结果(也不需要
if语句)。 -
你用
__in试过了吗?那应该对你有帮助。查看更多here -
@thebjorn 你是什么意思?我的确切问题是如何申请 | (组合运算符)用于列表中的所有查询集。我还应该提供哪些其他信息?
-
请指定您要应用的其他过滤器。预期结果如何?
标签: python django django-models