django-modeltranslation
django-modeltranslation copied to clipboard
Fallback on foreignkey don’t return translation when we use values method.
When I try to keep translated string from foreign object by a queryset.values(), the query don’t fallback on translated field.
Use case:
class Foo(models.Model):
id = models.AutoField(primary_key=True)
term_name = models.CharField(…) #translated field
class FooOptions(TranslationOptions):
fields = ('term_name',)
empty_values = ''
translator.register(Foo, FooOptions)
class Bar(models.Model):
id = models.AutoField(primary_key=True)
foo = models.ForeignKey(Foo, …)
Foo.objects.values('term_name') return the translated value.
Query: SELECT "foo"."term_name_fr", "foo"."term_name_en" FROM "foo"
But Bar.objects.values('foo__term_name') return the original value.
Query: SELECT "foo"."term_name" FROM "bar" INNER JOIN "foo" ON ("bar"."foo_id" = "foo"."id")
Ha, that's because Bar is not registered for translation, is it? And as a consequence, its manager is not multiligual-aware...
Try registering Bar for translation with empty fields.
Hi thx for the reply, that’s right Bar wasn't registered for translation.
So I tried your solution but nothing change.
Using values on foreignkey don’t try to retrieve translated field.
Duplicate of #345