I have a scenario where i must specify the language in my query every time I execute objects.filter from model. For translation purposes, whereby I must send the request.LANGUAGE_CODE as mandatory field.
In my model.py
class ModelA(models.Model):
field_a = models.CharField(max_length=1, choices=_statuses, default=_default_status)
field_b = models.ForeignKey(ModelLookup, )
language = None
def i18n(self):
return self.model.modellookupi18n_set.values_list('make_display', 'model_display', 'trim_display').get(language=self.language)
Is there a way for me to specify language value when I run ModelA.objects.filter() for example, if possible for me to pass it as a chained parameter otherwise class fails to run.
You can get active language from django.utils.translations through get_language() method:
This is the right way to work with languages.