如何使用 ModelForm 和 ModelFormSet
我只想澄清一下。我正在阅读 Django 表单向导文档
在文档中,它谈到表单向导能够与 ModelForm 和 ModelFormSet 一起“工作”。我想澄清这意味着什么。这是否意味着表单向导可以通过模型将表单的发布数据直接保存到数据库中?
我将模型的实例作为 instance_dict 参数中的参数传递,但没有成功。当我提交表单时,表单会被处理,但没有任何内容发送到数据库。
谢谢
I just want some clarification. I'm working through the Django Form Wizard documentation
In the documentation it talks about the Form Wizard being able to 'work' with ModelForm and ModelFormSet. I want clarification on what this means. Does it mean that the Form Wizard can save the post data of a form straight to the database via the model?
I'm passing the instance of a model as an argument in the instance_dict parameter without success. When I submit the form the form gets processed but nothing is sent to the database.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,它不会自动保存表单信息!
通常您需要在您的视图中处理表单。
ModelForm
基本上只是一个帮助器,可以使模型实例编辑/创建更容易,当然对于前端来说也更原生。因此,您通常会在您的视图中执行以下操作(简而言之):有关更多详细信息,您应该检查 有关如何使用表单的文档和ModelForm 文档< /a>.直接使用 FormWizard 开始可能不是一个好主意。 :)
No, it is not saving the form information automatically!
Usually you need to process the form in your view. A
ModelForm
is basically just a helper to make model instance edting/creating easier and of course more native for your frontend. So here something you usually would do in your view (in short):For more details you should check the docs about how to work with forms and the ModelForm documentation. Starting direclty with the FormWizard wasn't maybe such a good idea. :)