【发布时间】:2019-01-23 22:39:31
【问题描述】:
我从 Django 1.10 升级到 1.11,现在我以前工作的两个模型导致错误。它们是仅有的两个具有 ManyToManyField 且包含 related_name 属性的模型。我有另一个ManyToManyField 没有related_name,它工作正常。
抛出的错误具有误导性:
<class 'hadotcom.admin.CaseStudyAdmin'>: (admin.E012) There are duplicate field(s) in 'fieldsets[0][1]'
我找到了引用该错误的其他 SO 帖子,并确认它们都不符合我的问题。
如果我注释掉整行,它就会通过检查。我尝试添加 through 属性,但没有帮助。
示例代码(使用夹层):
class CaseStudyPage(Page):
industries = models.ManyToManyField("IndustryPage", blank=True, related_name="industry_set", through="CaseStudyIndustries")
class CaseStudyAdmin(HaPageAdmin):
inlines = (Foo, Bar,)
很高兴填写任何空白,并提前致谢。
【问题讨论】:
-
如果
"IndustryPage"是模型,则删除引号。 -
感谢@Ahtisham,但我将它放在引号中,以便我可以延迟加载它,因为它稍后在文件中定义。
-
向我们展示
CaseStudyAdmin代码。 -
所见即所得。这两个内联是基本模型,即使我删除它们也会引发相同的错误。