Model.save() 和 ModelForm.save() 一起工作
Model.save() and ModelForm.save() works together
我是 django 的新手。我想知道 Django 中的 ModelForm 和 Model 如何协同工作?我的意思是 ModelForm.save() 如何自动保存与之关联的模型?它如何根据 request.POST 信息创建模型?
请举例说明。
提前致谢。
来自https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#the-save-method:
Every ModelForm also has a save() method. This method creates and saves a database object from the data bound to the form.
页面上也有示例。
开源软件的好处之一是您不必询问它是如何工作的,因为您只需阅读代码即可:https://github.com/django/django/blob/master/django/forms/models.py
我是 django 的新手。我想知道 Django 中的 ModelForm 和 Model 如何协同工作?我的意思是 ModelForm.save() 如何自动保存与之关联的模型?它如何根据 request.POST 信息创建模型?
请举例说明。
提前致谢。
来自https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#the-save-method:
Every ModelForm also has a save() method. This method creates and saves a database object from the data bound to the form.
页面上也有示例。
开源软件的好处之一是您不必询问它是如何工作的,因为您只需阅读代码即可:https://github.com/django/django/blob/master/django/forms/models.py