[Answered ]-Django: Save to a many-to-many field in a ModelForm's save() method?

2👍

The most immediate issue in your code is that when the save() method is called by the Django admin, the commit argument is almost always False. However, if you simply ignore the value of commit, you will not be able to do model.post_meta.add(pm) for newly created Posts, since the model will not have been created in the database yet (and hence cannot be referred to in the Post to PostMeta m2m table).

See my answer to a different post, which I think is also applicable in your case, and has quite a bit of code that you may find useful.

Leave a comment