I have a model such as below:
class MyModel(TranslatableModel):
date_created = models.DateField(
verbose_name=_('Date Created'), default=timezone.now)
source = models.CharField(max_length=100, verbose_name=('Type'))
translations = TranslatedFields(
name=models.CharField(verbose_name=_('Name'), max_length=200)
)
I want to use update_or_create function on this model; I want to fetch a record which has the given id and source; If it exists I want to update its name in 3 different languages. Otherwise I want to create a new record. I used the following code. I tried name_en, name__en, translations__name_en; None of them worked. I also tried get_or_create function, None of them worked with that as well.
obj, created = MyModel.objects.update_or_create(
id= id,
source = 'tmp',
defaults={
'name_en': en_name,
'name_fi': fi_name,
'name_sv': sv_name,
})
I don't want to use get function and create function separately. I would like to know how to access the django translated fields via update_or_create function or get_or_create function. Can some one help me with this please?
My Django version: Django==1.11.17
update_or_create creates object/updates object fields and it is not built to create related models/update fields on related model
And as documented
Also same is visible from source