How to reuse Django's SQL compiler?

Viewed 223

I needed to perform an UPDATE JOIN query but django has no builtin support for that, so I wrote a raw SQL query. But now I need to build the where clause of that query dynamically, so I would like to know how to reuse Django's SQL compiler.

I could take the Query object from Model.objects.filter(...).query, then generate the raw SQL of the where clause with query.where.as_sql(query.get_compiler(using='default'), None) but the tables from my current raw SQL are aliased, so the lookup fields will be wrong.

0 Answers
Related