[Answered ]-Modify form fields in FormWizard (Django 1.4)

2๐Ÿ‘

I solved this by overriding get_form_kwargs for the WizardView. It normally just returns an empty dictionary that get_form populates, so by overriding it to return a dictionary with the data you need prepopulated, you can pass kwargs to your form init.

def get_form_kwargs(self, step=None):
    kwargs = {}
    if step == '1':
        your_data = self.get_cleaned_data_for_step('0')['your_data']
        kwargs.update({'your_data': your_data,})
    return kwargs

Then, in your form init method you can just pop the kwarg off before calling super:

self.your_data = kwargs.pop('your_data', None)

and use that value to perform whatever logic you need to on the form.

๐Ÿ‘คNick Gottlieb

0๐Ÿ‘

๐Ÿ‘คVoSi

Leave a comment