Django FormWizard prefill编辑

问题描述 投票:1回答:1

我正在使用FormWizard编辑对象,我希望能够在加载编辑页面时预填充数据库中的字段。

例如,如果我的URL是'category_edit_wizard / 5',则字段'title'应该具有加载页面时ID为5的类别的值。

有办法吗?

谢谢

django django-forms django-formwizard
1个回答
2
投票

如果你正在使用Django 1.4中引入的django-formwizard或新的formwizard实现,你可以使用ModelForm作为步骤形式,并在创建WizardView实例时传递instance_dict。

instance_dict与initial_dict的工作方式相同 - 请参阅https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.initial_dict

如果您正在使用Django 1.3及更低版本的旧formwizard实现,您可以按照此处所述传递初始值:https://django-formtools.readthedocs.io/en/latest/wizard.html#providing-initial-data-for-the-forms

© www.soinside.com 2019 - 2024. All rights reserved.