Django模型错误 - “TypeError:'xxx'是此函数的无效关键字参数

时间:2011-12-30 08:53:39

标签: python django django-models

我收到错误:

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 = [])

1 个答案:

答案 0 :(得分:27)

  1. 在没有多少人的情况下实施您的模型investment1 = Investment()

  2. 保存模型investment1.save()

  3. 添加多对investment1.person.add(person_model)investment1.person.create(name='foo')

  4. several ways to do it

    在保存模型之前,您可能不会使用ManyToMany关系,这是因为ManyToMany关系表中的行需要关系两侧的模型的pk。