简体   繁体   English

Django结合两个没有Q的查询

[英]Django combine two queries without Q

This is the problem I am currently having: 这是我目前遇到的问题:

I filter out models using Q() and get x results. 我使用Q()过滤掉模型并得到x个结果。 I then examine x results to determine certain conditions. 然后,我检查x结果以确定某些条件。 Depending on those condition, I perform another query and get y results. 根据这些条件,我执行另一个查询并获得y结果。 It's at this point that I would like to combine x results and y results and then perform a filter on both. 正是在这一点上,我想将x结果和y结果合并,然后对两者进行过滤。 Keep in mind that both queries are of the same model. 请记住,两个查询的模型相同。

Since I cannot perform query 2 until I have results from Query 1, it's not possible to combine these 2 queries using Q(). 由于只有在获得查询1的结果后才能执行查询2,因此无法使用Q()合并这两个查询。

Is there some sort of way that I can combine the results together? 有什么方法可以将结果组合在一起? Basically what I am trying to achieve would sort of look like this: 基本上,我想达到的目标是这样的:

all_results = x_results.extend(y_results)
all_results.filter(price = 500)

我想你可以做这样的事情

all_results = x_results | y_results

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM