开发者

Django FormWizard prefill on edit

开发者 https://www.devze.com 2023-03-02 18:21 出处:网络
I\'m using a FormWizard to edit objects and I want to be able to prefill the fields from database when the edit page is loaded.

I'm using a FormWizard to edit objects and I want to be able to prefill the fields from database when the edit page is loaded.

For example if my URL is 'category_edit_wizard/5', the field 'title' should have the 开发者_运维百科value of the category with the ID 5 when the page is loaded.

Any way to do that?

Thank you


If you're using django-formwizard or the new formwizard implementation introduced in Django 1.4 you can use ModelForm's as a step form and pass an instance_dict when creating the WizardView instance.

instance_dict works the same way initial_dict works - see https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.initial_dict

If you're using the old formwizard implementation from Django 1.3 and lower, you can pass initial as described here: https://django-formtools.readthedocs.io/en/latest/wizard.html#providing-initial-data-for-the-forms

0

精彩评论

暂无评论...
验证码 换一张
取 消