How to add multiple objects to ManyToMany relationship at once in Django ?

Use: object.m2mfield.add(*items) as described in the documentation:

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

Addendum:

Django does not call obj.save() for each item but uses bulk_create(), instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)