How to set the value of the original field with django modeltranslation?

Viewed 37

I've been adding German model translations using django-modeltranslation and I found out that I've accidentally set the original field values (that are supposed to be in English) to German. So now in the database I have:

  • name: German value (should be English)
  • name_en: English (correct)
  • name_de: German (correct)

Is there a way to copy over the name_en values to name either in Python or directly in PostgreSQL? I've read the access/read rules but I'm not 100% sure how they impact what I want to do.

1 Answers

Found a solution to fix it without going to the DB level.

from django.utils.translation import activate


activate('en')

for x in Model.objects.all():
    setattr(x, 'name', x.name)
    x.save()
Related