Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerySet: LEFT JOIN with AND
    text
    copied!<p>I use old Django version 1.1 with hack, that support join in extra(). It works, but now is time for changes. Django 1.2 use RawQuerySet so I've rewritten my code for that solution. Problem is, that RawQuery doesn't support filters etc. which I have many in code. Digging through Google, <a href="http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/" rel="noreferrer">on CaktusGroup</a> I've found, that I could use query.join(). It would be great, but in code I have: </p> <pre><code>LEFT OUTER JOIN "core_rating" ON ("core_film"."parent_id" = "core_rating"."parent_id" AND "core_rating"."user_id" = %i </code></pre> <p>In query.join() I've written first part <code>"core_film"."parent_id" = "core_rating"."parent_id"</code> but I don't know how to add the second part after AND.<br> Does there exist any solution for Django, that I could use custom JOINs without rewritting all the filters code (Raw)?</p> <p>This is our current fragment of code in extra() </p> <pre><code>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'], ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload