I am using an old version of Django 1.1 with a hack that supports connection in extra (). It works, but now is the time for change. Django 1.2 uses RawQuerySet, so I rewrote my code for this solution. The problem is that RawQuery does not support filters, etc., which I have a lot in the code. Digging through Google, in CaktusGroup I found that I can use query.join (). It would be great, but in the code I have:
LEFT OUTER JOIN "core_rating" ON ("core_film"."parent_id" = "core_rating"."parent_id" AND "core_rating"."user_id" = %i
In query.join (), I wrote the first part of "core_film"."parent_id" = "core_rating"."parent_id" , but I donβt know how to add the second part after AND.
Is there any solution for Django that I could use custom JOINs without overwriting all the filter code (Raw)?
This is our current code snippet in extra ()
top_films = top_films.extra( select=dict(guess_rating='core_rating.guess_rating_alg1'), join=['LEFT OUTER JOIN "core_rating" ON ("core_film"."parent_id" = "core_rating"."parent_id" and "core_rating"."user_id" = %i)' % user_id] + extra_join, where=['core_film.parent_id in (select parent_id from core_film EXCEPT select film_id from filmbasket_basketitem where "wishlist" IS NOT NULL and user_id=%i)' % user_id, '( ("core_rating"."type"=1 AND "core_rating"."rating" IS NULL) OR "core_rating"."user_id" IS NULL)', ' "core_rating"."last_displayed" IS NULL'], )
Dariusz smigiel
source share