I have two models:
class Video(models.Model):
slug = models.SlugField(blank=True, default='', db_index=True, unique=True)
class VideoTranslation(models.Model):
video = models.ForeignKey(Video, related_name='translations')
language = models.CharField(max_length=3, choices=settings.LANGUAGES)
name = models.CharField(max_length=255, db_index=True)
Video contains some infromation about video, Video translation contains translated names of these videos.
I want to get itmes from Video model in one of languages.
It is possible by sql query like this:
SELECT * FROM video_video IN join video_videotranslation ON video_video.id = video_videotranslation.video_id where video_videotranslation.language="en" ORDER BY video_videotranslation.name;
but I really want to avoid raw sql queries.
Is it possible to make this kind of query rellying only on Django ORM?
Absolutely, it will look like:
See lookups that span relationships for the syntax, and the documentation of order_by.