django-modeltranslation 成为可翻译中已经存在的字段

django-modeltranslation become a already exists field in translatable

我正在使用 django-modeltranslation 来翻译我应用中的模型。我有一个模型,我已经使用迁移命令与数据库同步。我也有很多关于那个模型的记录。

class Home(models.Model):
    description = models.TextField()

当然,此时,我可以从数据库中检索描述字段

h = Home.objects.first()
h.description # --> "This home is near to..."

现在,我想使用 django-modeltranslation 成为 description 字段 translatable。我已经按照指南,我已经在 translation.py 文件中注册了翻译模型,最后我执行了 makemigrationsmigrate 命令。这添加到我的数据库中,在 home table 中,字段 description_endescription_es,因为我可用的语言是enes,前者是默认的。

此时我需要填充 description_en 字段,这是任何查询的默认字段,我试过

Home.objects.all().update(description_en=F('description')) 

但它不起作用,因为当它尝试访问 description 字段时,它实际上是在尝试访问 description_en,它是空的:

h = Home.objects.first()
h.description # --> '' Empty?!!!

我检查过数据是否仍在数据库中,它们确实在!

我的问题是:如果描述数据仍在数据库中,并且h.description 实际上检索我 h.description_en,如何为 [=28= 中的所有数据填充 description_en ]描述字段?

阅读这篇文章,我意识到模型翻译附带的管理命令的存在,它填充默认语言:python manage.py update_translation_fields