我得到错误:
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 = [])
最佳答案
在没有多对多的情况下实例化您的模型,
investment1 = Investment()
保存您的模型,
investment1.save()
多对多相加,有several ways to do it像
investment1.person.add(person_model)
或investment1.person.create(name='foo')
在保存模型之前,您不能使用 ManyToMany 关系,这是因为 ManyToMany 关系表中的一行需要关系两侧模型的 pk。
关于python - Django 模型错误 - "TypeError: ' xxx' 是此函数的无效关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8677750/