I have a model like this:
from django.db import models
from django.utils.translation import ugettext_lazy as _
from parler.models import TranslatableModel, TranslatedFields
...
class UnitNode(TranslatableModel):
...
translations = TranslatedFields(
title=models.CharField(_(u'title'), max_length=1024),
slug=models.SlugField(_('slug'))
),
)
...
I want a QuerySet of UnitNodes without duplicates, sorted by slug. When I query something like this:
qs = UnitNode.objects.distinct().order_by("translations__slug")
I get duplicates.
How do I get rid of duplicates?
The solution is:
This way you only get the instances for the current language in use in the app and it won't generate duplicates. Just as you were doing it gets all instances of all languages by duplicating itself in different languages.