我收到错误:
TypeError: 'person' is an invalid keyword argument for this function
我的模特是:
class Investment(models.Model):
company = models.ManyToManyField("Company", related_name ="Investments_company")
financial_org = models.ManyToManyField("Financial_org", related_name ="Investments_financial_org")
person = models.ManyToManyField("Person", related_name ="Investments_person")
我的测试(给出错误):
investment1 = Investment(company = [], financial_org = financial1, person = [])
答案 0 :(得分:27)
在没有多少人的情况下实施您的模型,investment1 = Investment()
保存模型,investment1.save()
添加多对,investment1.person.add(person_model)
或investment1.person.create(name='foo')
在保存模型之前,您可能不会使用ManyToMany关系,这是因为ManyToMany关系表中的行需要关系两侧的模型的pk。