I don't think so. The ManyToMany relationship is realized with an intermediate table than contains (id, a_id, b_id) tuples. Therefore A must pre-exist (See 'Sample API Usage') and each B must have an id
before the intermediate row can be created. I looked at the source in django.db.models.fields.related
and although create_many_related_manager
has a method called _add_items()
, it seems to assume that all of the B items being added already have id
fields, meaning they must have been saved beforehand.
I couldn't find anything that would allow the equivalent of A.add(bunch_of_Bs_that_havent_been_saved_yet)
. The above mentioned example does show add()
ing multiple Bs in one shot, but they have all been saved before the add()
happens. Sorry.