Django ModelTranslation本地字段与父级的模型字段冲突

2024-10-05 14:30:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Mezzanine开发一个网站,我在为它配置modelTranslation插件时遇到了问题,我使用的是Django1.8.9和Mezzanine 4.0.1,Django_nuModelTranslation 0.11。在

我有一个模型类GenericContent,其中包含一些字段:

class GenericContent(models.Model):
    image_footer = RichTextField(blank=True)
    video_footer = RichTextField(blank=True)
    summary = RichTextField(blank=True)

class BasicContent(Page, RichText, GenericContent):
    pass

在翻译.py对于basicContent应用程序,我们有以下modelTranslation翻译定义:

^{pr2}$

使用这种配置,它不会显示错误,但是basicContent不会被翻译(从genericContent继承的字段被注册用于翻译,但是在basicContent中,它们不会被翻译,父类[Page和RichText]中的任何其他字段也不会被翻译,它们是夹层包含的类,并注册用于翻译)。在

如果我试图修改翻译.py文件:

class TranslatedGenericContent(TranslationOptions):
    fields = ('summary',
              'image_footer',
              'video_footer',)

translator.register(GenericContent, TranslatedGenericContent)
translator.register(BasicContent, TranslatedGenericContent)

另一种配置在尝试运行python时会出错管理.py同步翻译字段

basicContent.BasicContent.image_footer_en: (models.E006) The field 'image_footer_en' clashes with the field 'image_footer_en' from model 'basicModels.genericcontent'.
basicContent.BasicContent.image_footer_es: (models.E006) The field 'image_footer_es' clashes with the field 'image_footer_es' from model 'basicModels.genericcontent'.
basicContent.BasicContent.summary_en: (models.E006) The field 'summary_en' clashes with the field 'summary_en' from model 'basicModels.genericcontent'.
basicContent.BasicContent.summary_es: (models.E006) The field 'summary_es' clashes with the field 'summary_es' from model 'basicModels.genericcontent'.
basicContent.BasicContent.video_footer_en: (models.E006) The field 'video_footer_en' clashes with the field 'video_footer_en' from model 'basicModels.genericcontent'.
basicContent.BasicContent.video_footer_es: (models.E006) The field 'video_footer_es' clashes with the field 'video_footer_es' from model 'basicModels.genericcontent'.

你有没有经历过这个问题?我正在寻找解决办法。任何帮助都将不胜感激!在


Tags: theimagefieldesmodelsvideowithsummary