I have two classes:
class Translation(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
object = generic.GenericForeignKey('content_type', 'object_id')
field = models.CharField(max_length=64) #field from the translated model
language = models.CharField(max_length=8, choices=settings.LANGUAGES, verbose_name=_("language"))
text = models.TextField() #translation
class Category(models.Model):
translations = generic.GenericRelation(Translation)
name = models.CharField(max_length=128, verbose_name=_("Name"))
slug = models.SlugField(blank=True, default="", verbose_name=_("Slug"))
Is there a way to order Categories by translation__text filtering the order_by by the current language? If I use
Category.objects.all().order_by("translations__text")
I get categories sorted by all translations, not just the current language. I guess, what I ned is filtering the order_by set somehow (to use only translations of a given language)? Is there a way to do so?
DB = PostgreSQL
Thanks for help!
Try this: