You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from .modelsimportObjectfromdjango.utilsimporttranslationfromdjango.db.modelsimportFtranslation.activate("pt-br")
Object.objects.ceate(name_en_us='Test', name_pt_br='Teste')
print(Object.objects.first().name) # prints 'Teste'print(Object.objects.annotate(test_name=F('name')).first().test_name) # prints 'Test'
The expected behavior should be:
print(Object.objects.annotate(test_name=F('name')).first().test_name) # prints 'Teste'
The text was updated successfully, but these errors were encountered:
@CefasR
I agree. I also encountered this issue. It would be awesome, if someone patched this.
For now, since I also ran into this problem using F-expressions, I used this dirty hack:
print(Object.objects.annotate(test_name=TranslatedF('name')).first().test_name) # prints 'Teste'
I chose to override the F.resolve_expression method to delay the get_language call as much as possible to have a better chance to resolve properly. The easier way would have been to override the F.__init__ method and simply replace the self.name attribute with the language-specific field name, but then the language would have to be defined during the F-object's initialization.
Anyway, this worked for me in a specific situation.
I couldn't figure out, where to even begin with a "proper" patch. Hope someone more skilled gets on that.
Consider the following case:
models.py
file:translation.py
file:Current bahavior:
The expected behavior should be:
The text was updated successfully, but these errors were encountered: