#Applying QuerySet.order_by after union

2 messages · Page 1 of 1 (latest)

vague marsh
#

I am starting off with a single query set which has an additional field (from another model) selected using .extra(). This query set is a base for creating multiple other query sets, that are then combined into 1 using QuerySet.union(). I'm able to apply ordering by any field from the original model, but when i try to set order by the additional extra field it always raises exceptions.
I've tried many things, my last idea was to get QuerySet.query and manually add " ORDER BY (1) DESC", but it didn't to work because QuerySet.query doesn't seem to return proper "ready-to-run" SQL, and Oracle was throwing error.
I'm not really able to provide exact model structures, because this is a commercial project and i wouldn't want to run into any trouble, but if it helps visualising the problem i can make up an example.

neon karma