我从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
属性,但没有帮助。
示例代码(使用Mezzanine):
class CaseStudyPage(Page):
industries = models.ManyToManyField("IndustryPage", blank=True, related_name="industry_set", through="CaseStudyIndustries")
class CaseStudyAdmin(HaPageAdmin):
inlines = (Foo, Bar,)
很高兴填写任何空白,并提前感谢。
似乎ContentTypedAdmin
中的Mezzanine
在子类中添加两次ManyToMany
字段。我没有调查它究竟发生的原因。一个可能的解决方案是将ContentTypedAdmin.__init__()
的最后两行改为:
if not hasattr(field, "translated_field") and field.name not in self.fieldsets[0][1]["fields"]:
self.fieldsets[0][1]["fields"].insert(3, field.name)