Django form with many-to-many relationship does not save

谁说胖子不能爱 提交于 2019-12-01 03:40:51
Daniel Robinson

Since you use commit=false for the super(RegistrationForm, self).save call, it doesn't save the many-to-many field. You therefore need to add self.save_m2m() after user.save() in your save() method of RegistrationForm.

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

EDIT: save_m2m() is on the Form, not the Model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!