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

时间:2016-03-14 11:50:29

标签: python django django-models mezzanine django-modeltranslation

我正在开发一个Mezzanine的网站,我在尝试为它配置modelTranslation插件时遇到了问题。我使用的是Django 1.8.9和Mezzanine 4.0.1,django_modeltranslation 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

在basicContent应用程序的translation.py文件中,我们有以下modelTranslation翻译定义:

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

class TranslatedBasicContent(TranslationOptions):
    pass

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

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

如果我尝试修改translation.py文件:

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

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

此其他配置在尝试运行 python manage.py sync_translation_fields

时出现错误
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'.

你有没有遇到过这个问题?我正在寻找解决方案。任何帮助将不胜感激!

0 个答案:

没有答案