When translations are added to any translated field, the main object appears once for every translation in the results. It happens in the admin too: I can see eg. 2 entries referring to the same object id, and they are displayed with the same translation, so that it looks like a duplicate record.
I tried to solve with a custom manager but I get errors here and there.
This is my code:
class ProfessionManager(MultilingualManager):
def filter(self, *args, **kwargs):
# Get base queryset, caching translations
qs = self.get_query_set().select_related('translations')
# Check if there's a language filter
if not kwargs.get('translations__language_code'):
kwargs['translations__language_code'] = get_language()[0:2]
qs = qs.filter(*args, **kwargs)
return qs
def all(self):
return self.filter()
class Profession(models.Model):
objects = ProfessionManager()
class Meta:
ordering = ('translations__name',)
class Translation:
name = models.CharField(_('name'), max_length=200)
description = models.TextField(_('description'),blank=True,null=True)
def __unicode__(self):
return u"%s" % (self.name_any)
This is causing me problems when I attach this models as a m2m, because related objects multiply as soon as I add translations.
Is this by design, and if so, is there any method you suggest to solve it?
When translations are added to any translated field, the main object appears once for every translation in the results. It happens in the admin too: I can see eg. 2 entries referring to the same object id, and they are displayed with the same translation, so that it looks like a duplicate record.
I tried to solve with a custom manager but I get errors here and there.
This is my code:
This is causing me problems when I attach this models as a m2m, because related objects multiply as soon as I add translations.
Is this by design, and if so, is there any method you suggest to solve it?
Thanks!