[Answered ]-How to insert data into ManyToManyField in django from views.py

2👍

add() accepts an arbitrary number of arguments, not a list of them.

add(obj1, obj2, obj3, ...)

To expand that list into arguments, use *

add(*[obj1, obj2, obj3])

use this as (@EchoUA Team) mentioned in comments

items = list(item)
q.item.add(*items)

0👍

You are missing the second “save()” call.

q = Catalog(title=title, pub_date=timezone.now(),user=user)
q.save()
q.item = item.values()
q.save()       # you need this save as well
👤Du D.

Leave a comment