Search code examples
pythondjangodatabasepostgresqldjango-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. 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)

Solution

  • I think you can do something like this

    all_results = x_results | y_results