About Setting Many-to-many Relationships

Use the set() method of many-to-many relationship manager, to set the value to a list of objects. For example,

django_cookbook.authors.set([aidas, jake])

is equivalent to

django_cookbook.authors.clear()
django_cookbook.authors.add(aidas)
django_cookbook.authors.add(jake)

Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2