使用ManyToManyField时重复的字段

问题描述 投票:0回答:1

我从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,)

很高兴填写任何空白,并提前感谢。

python django mezzanine
1个回答
1
投票

似乎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)
© www.soinside.com 2019 - 2024. All rights reserved.