Python Django:相关名称反向访问器
我有一个模型,其中InstitutePerson是Person的一个子类Python Django:相关名称反向访问器,python,django,Python,Django,我有一个模型,其中InstitutePerson是Person的一个子类 人 学院人事 计划 在项目中: participants_institite = models.ManyToManyField(InstitutePerson, blank = True, null = True) participants_exterior = models.ManyToManyField(Person, blank = True, null = True) 我得到一个错误: Project.p
- 人
- 学院人事
- 计划
participants_institite = models.ManyToManyField(InstitutePerson, blank = True, null = True)
participants_exterior = models.ManyToManyField(Person, blank = True, null = True)
我得到一个错误:
Project.participants_institute: (fields.E304) Reverse accessor for 'Project.participants_institute' clashes with reverse accesor for 'Project.participants_exterior'.
我原以为related_name可以解决这个问题,但在看到一些帖子()之后,我不确定如何继续,因为类之间存在继承关系。使用
related_name
arg并手动定义它
如果有两个类型相同的M2M字段,Django无法自动在目标modela上生成属性
如果你对相反的方向不感兴趣,你可以简单地使用ise
models.ManyToManyField(…,相关_name='+r1')
models.ManyToManyField(…,相关_name='+r2')