[Django]-Saving Many To Many data via a modelform in Django

69👍

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method

When using commit=False, you have to call save_m2m()

m2m relationships require the parent object to be saved first, which you are not doing by using commit=False

22👍

You can do like this
for example:

  if todo_list_form.is_valid():
                todo_list = todo_list_form.save(commit=False)
                todo_list.save()
                todo_list_form.save_m2m()
👤Wagh

Leave a comment