I have a Django queryset where I have to use the .extra(select=)
method, since I'm calculating a field that requires a WHERE
statement subfilter.
I use this WHERE
clause in a number of places, and I'd like to be obeying DRY (which is usually somewhat difficult when writing raw SQL). I have written a statement using Django's Q()
objects that I could reuse and add into the raw SQL.
I know that you can do Queryset.query.__str__()
to get the equivalent SQL output--is there a way to do this with Q
objects?