I have three querysets of the same columns that I would like to handle as one object. At the moment I am doing:
queryset.union(qs1, qs2)
The downside is that I lose access to queryset.order_by(). Is there a way around this? I mean, those querysets came from the same model but were generated by different queries.
If they are two queries on the same model, then you could probably do this as one query, with the respective filters joined as Q objects with an or condition.
While that is feasible, it is giving me unexpected output results.
I am also finding that my observation about queryset unions is partially wrong. I get results sometimes. Sometimes I get errors. It appears to fail more on chained unions (e.g qs.unon(qs1, qs2).union(qs3))
queryset.union(qs1, qs2).order_by("field") works
Whereas queryset.union(qs1, qs2).order_by("field__subfield") throws a StopIteration Error