Django

Code

Ticket #7231 (new)

Opened 2 months ago

New "join" parameter for the "extra" QuerySet method

Reported by: Davide "Design" Muzzarelli Assigned to: nobody
Milestone: Component: Core framework
Version: SVN Keywords: queryset extra join
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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.

Attachments

extra-join.diff (2.4 kB) - added by Davide "Design" Muzzarelli <info@dav-muz.net> on 05/13/08 16:20:39.
New parameter "join" for the QuerySet?.extra() function.

Change History

05/13/08 16:20:39 changed by Davide "Design" Muzzarelli <info@dav-muz.net>

  • attachment extra-join.diff added.

New parameter "join" for the QuerySet?.extra() function.


Add/Change #7231 (New "join" parameter for the "extra" QuerySet method)




Change Properties
Action