Search code examples
pythondjangodjango-modeltranslation

django model translation - filter by translated field


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?


Solution

  • Use kwargs,

    kwargs = {
        f"title_{language}": "some title"
    }
    MyModel.objects.filter(**kwargs)