DGDD
DGDD

Reputation: 1390

Django combine two queries without Q

This is the problem I am currently having:

I filter out models using Q() and get x results. I then examine x results to determine certain conditions. Depending on those condition, I perform another query and get y results. It's at this point that I would like to combine x results and y results and then perform a filter on both. 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().

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)

Upvotes: 0

Views: 105

Answers (1)

Rod Xavier
Rod Xavier

Reputation: 4043

I think you can do something like this

all_results = x_results | y_results

Upvotes: 3

Related Questions