在 Django 中设置表单集的输出值
这个问题在某种程度上与我之前问过的问题有关:
我想知道,如果表单集中的每个表单都有单独的默认值,我是否能够预填充田野? 例如,需要用用户名预先填充额外客户信息的表单? 在向现有表添加电子邮件字段并立即更新其中许多字段的情况下。
Django 提供了一种简单的方法来做到这一点吗?
This question is somewhat linked to a question I asked previously:
Generating and submitting a dynamic number of objects in a form with Django
I'm wondering, if I've got separate default values for each form within a formset, am I able to pre-populate the fields? For instance, a form requiring extra customer information to be pre-populated with the users names? In cases like adding an email field to an already existing table, and updating many of them at once.
Does Django provide an easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
传入一个字典列表,其中包含要为每个表单设置的默认值:
http://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-initial-data-with-a-formset
Pass in a list of dicts which contain the default values you want to set for each form:
http://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-initial-data-with-a-formset