Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django model error- "TypeError: 'xxx' is an invalid keyword argument for this function

I get the error:

TypeError: 'person' is an invalid keyword argument for this function

My model is:

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")

My test (that gives the error):

investment1 = Investment(company = [], financial_org = financial1, person = [])
like image 387
Riku Avatar asked Dec 30 '11 08:12

Riku


1 Answers

  1. Instanciate your model without many to many, investment1 = Investment()

  2. Save your model, investment1.save()

  3. Add many to many, there are several ways to do it like investment1.person.add(person_model) or investment1.person.create(name='foo')

You may not use a ManyToMany relation until a model is saved, this is because a row in a ManyToMany relation table needs the pk of the models at the two sides of the relations.

like image 130
jpic Avatar answered Sep 20 '22 01:09

jpic