[Django]-Add an object by id in a ManyToMany relation in Django

53👍

Although the documentation of the add method does not mention it, you can actually pass directly an id to it, like this:

my_instance.add(id)

Surely, this only works when the primary key is used as the identifier for the relation (the default behaviour).

Leave a comment