Django FormWizards: How to painlessly pass user-entered data between forms?

前端 未结 1 1054
醉话见心
醉话见心 2021-01-06 18:31

I\'m using the FormWizard functionality in Django 1.4.3.

I have successfully created a 4-step form. In the first 3 steps of the form it correctly takes information f

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 19:05

    Try this:

    def get_context_data(self, form, **kwargs):
        previous_data = {}
        current_step = self.steps.current # 0 for first form, 1 for the second form..
    
        if current_step == '3': # assuming no step is skipped, this will be the last form
            for count in range(3):
                previous_data[unicode(count)] = self.get_cleaned_data_for_step(unicode(count))
    
        context = super(my4StepWizard, self).get_context_data(form=form, **kwargs)
        context.update({'previous_cleaned_data':previous_data})
        return context
    

    previous_data is a dictionary and its keys are the steps for the wizard (0 indexed). The item for each key is the cleaned_data for the form in the step which is the same as the key.

    0 讨论(0)
提交回复
热议问题