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
精彩评论