Django Formset没有实例 [英] Django Formset without instance

查看:79
本文介绍了Django Formset没有实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个中,Django Doc解释了如何创建一个可以编辑属于某个作者的书籍的表单。

In this Django Doc explain how to create a formset that allows you to edit books belonging to a particular author.

我想做的是:创建一个表单,允许您添加新书属于新作者...以相同的表格集添加图书及其作者。

What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Add the Book and their Authors in the same formset.

你可以轻松一点吗?谢谢。

Can you gime a light? thanks.

推荐答案

当您初始化显示的实例化表单和表单时,不需要提供一个实例 - 所以你只会得到空白的表单。

When you're instantiating the form and formset for the initial display, you don't need to provide an instance - so you will just get blank forms.

当您传递POST的数据时,您可以先执行表单,保存并获取一个实例。然后,您可以将该实例传递到表单集中,以便正确保存相关对象。

When you pass in the data on POST, you can do the form first, save it, and get an instance. Then you can pass that instance into the formset, so that it correctly saves the related objects.

这篇关于Django Formset没有实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆