Dynamic number of Steps using Django Wizard

前端 未结 3 1345
孤街浪徒
孤街浪徒 2020-12-06 22:49

Is possible that the steps of the wizard are dynamic? For example, the second step occur repeatedly n times?

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 23:15

    I struggled with this problem too. Tommaso Barbugli is right about creating a factory for the class. I'm currently working with Django 1.6.

    in the url, include this:

    url('/create_wizard/', factory_wizard, name='factory_wizard')
    

    this is the factory:

    class WizardClass(SessionWizardView):
        ...
    
    def factory_wizard(request, *args, **kwargs):
        parameter_to_know_which_step_number = #  I let you implement this one ( I did it by the session data )
        ret_form_list = [FirstFormClass, SecondFormClass]
    
        for _ in range(parameter_to_know...):
            form_list.append(SecondFormClass)
    
        class ReturnClass(WizardClass):
            form_list = ret_form_list
    
        return ReturnClass.as_view()(request, *args, **kwargs)
    

提交回复
热议问题