This "join" parameter for the "extra" QuerySet method add the possibility to use any join type.
The implementation is simple and resolve just the base needs of custom SQL queries without lose the capabilities of the Django ORM.
This feature could open the possibility of the fast translation of models and many other uses like speed optimizations in views.
An example from the News application:
class News(models.Model):
pub_date = models.DateField()
class NewsTranslation(model.Model):
title = models.CharField(max_length=128)
body = models.TextField()
language_code = models.CharField(max_length=2, core=True)
news = models.ForeignKey(News)
Getting all the news translated in english:
News.objects.extra(
select={'title': 'news_newstranslation.title', 'body': 'news_newstranslation.body'},
join=['LEFT JOIN news_newstranslation ON (news_news.id = news_newstranslation.news_id AND news_newstranslation.language_code = \'en\')']
)
The result of the query is a list of News with "title" and "body" attributes. The News without translation are also correctly fetched with the attributes "title" and "body" set at None.
The patch is post queryset-refactor.