[Fixed]-Django: Object is not iterable when trying to instantiate an object

1👍

RequestedPartners.player is a ManyToManyField. As per the documentation they have a special api when you need to assign values to them.

First, you need to save the RequestedPartners object (so that it has a primary key) then add the players:

rp1 = RequestedPartners()
rp1.last_nm = form['last_nm']
rp1.first_nm = form['first_nm']
rp1.save()
rp1.player.add(players)
rp1.save()

0👍

Attribute player is ManyToMany declaration. You can’t assign value like that, try this instead

rp1.player.add(players)

Leave a comment