django-modeltranslation
django-modeltranslation copied to clipboard
values() ignores current lang
>>> activate('en')
>>> Branch.objects.filter(pk=85017).values('name')
[{'name': 'Agriculture'}]
>>> Branch.objects.filter(pk=85017)[0].name
'Agriculture'
>>>
>>> activate('ru')
>>> Branch.objects.filter(pk=85017).values('name')
[{'name': 'Agriculture'}]
>>> Branch.objects.filter(pk=85017)[0].name
'\u0421\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u0445\u043e\u0437\u044f\u0439\u0441\u0442\u0432\u043e'
Seems like there is some problem when combining it with django-mptt
>>> Country.objects.filter(pk=1).values('name').__class__
<class 'django.db.models.query.FallbackValuesQuerySet'>
>>> Branch.objects.filter(pk=85017).values('name').__class__
<class 'django.db.models.query.ValuesQuerySet'>
Branch is a mptt model? What is Branch.objects.__class__ and Country.objects.__class__?
Yes, branch is MPTT model
>>> Country.objects.__class__
<class 'modeltranslation.manager.MultilingualManager'>
>>>
>>>
>>> Branch.objects.__class__
<class 'mptt.managers.TreeManager'>
That's the problem. TreeManager is used and not patched by modeltranslation.
Are you sure that Branch model is registered for translation?
Try to set MODELTRANSLATION_DEBUG = True in settings and see console output if there is Branch listed.
@register(Branch)
class BranchTranslationOptions(TranslationOptions):
fields = ('name', 'slug',)
modeltranslation: Registered 31 models for translation (..., Branch, ...) [pid: 96623].
I have a legacy django app ( in the same django project), there I have a model with the same name (Branch) but it have it's own translation.py file.