[Fixed]-M2m relations are not displayed or saved in django

1👍

It is not going to work. If you are using your own ManytoMany intermediary table, you have to manually manage and save the objects yourself. Using Django’s builtin functions won’t work.

Save Object A, then save Object B and then save the relation in your AtoB table (which is also an object).

a_to_b = AtoB.objects.create(a=object_a, b=object_b, user=self.request.user)
print(a_to_b)

[…] Note that if you are using an intermediate
model for a many-to-many relationship, some of the related manager’s
methods are disabled, so some of these examples won’t work with such
models.

https://docs.djangoproject.com/en/1.10/topics/db/examples/many_to_many/

Your error is explained here: https://docs.djangoproject.com/en/1.10/topics/db/models/#intermediary-manytomany

👤Ev.

Leave a comment