On Thu, Oct 06, 2011 at 12:05:09PM -0700, Attempting Django wrote: > Hi guys, can anyone please give me an example of how to do equivalent > of a LEFT JOIN ON in Django?? I am trying to return every row from one > table on the left, with any matches in a foreign table on the right > (there will be only one or NULL match possible). The issue I'm having > is showing left table data when there is a NULL on the right. Thanks! Django does this by default on nullable ForeignKeys. All you need to do is something like::
MyModel.objects.select_related('foreignkey_field')
Behind the scenes, Django does a JOIN. Its type (INNER od LEFT OUTER)
is decided based on whether the left-hand column (your ForeignKey
field) is allowed to be NULL or not.
Michal
signature.asc
Description: Digital signature

