I need to query like:
MyModel.objects.filter(title_de="some title")
where de inside title_de is dynamic
I cannot do:
MyModel.objects.filter('title_%s' % language = "some title")
how can I do this?
I need to query like:
MyModel.objects.filter(title_de="some title")
where de inside title_de is dynamic
I cannot do:
MyModel.objects.filter('title_%s' % language = "some title")
how can I do this?
If, in your example, language is the current language, then this will work out of the box. See the modeltranslation docs:
It works as follow: if the translation field name is used (
title), it is changed into the current language field name (title_deortitle_en, depending on the current active language). Any language-suffixed names are left untouched (sotitle_enwouldn’t change, no matter what the current language is).
There is no fallback in case there is no translation available for the given language (see e.g. this question), so this has the same effect as specifically querying a language-specific field.