Hi,
I have the necessity to make a LEFT JOIN for a "translated" model
object.

See the example:
"""
from django.db import models

class Bulletin(models.Model):
    pub_date = models.DateField()

class BulletinTranslation(model.Model):
    title = models.CharField(max_length=128)
    body = models.TextField()
    language_code = models.CharField(max_length=2, core=True)
    bulletin = models.ForeignKey(Bulletin)
"""

So a Bulletin object could have some translations.
The problem is that I need to display also the objects that have not
the translation in the current view language, so a LEFT JOIN is
basilar.

The behavior requested is that Bulletin have some extra fields from
BulletinTranslation or, at least, a cached BulletinTranslation in one
query (similar to select_related()).

A query for every Bulletin object, in order to get the correct
translation, is a problem because it explode the queries of my site
from 5 to more of 100 per page, so it is really a bad situation.

The other problem is that I can't use a raw SQL because I need some
important functions of the object in order to process some special
fields (not in the example).

The queryset-refactor documentation lacks, so it is very hard to
understand how to build a custom Q object.

This is very important for me, but I tried for an entire week on the
queryset-refactor without results.

How can I create a custom Q object in order to add a this simple LEFT
JOIN?

Example of the join:
"""
"SELECT bulletin.*, bulletintranslation.* FROM bulletin
LEFT JOIN bulletintranslation ON (bulletin.id =
bulletintranslation.bulletin_id AND bulletintranslation.language_code
= '%s');" % get_language_code()
"""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to