Django FormWizard Dynamically Alter form_list

前端 未结 1 625
醉话见心
醉话见心 2021-01-01 08:08

I\'m having some issues with the form wizard, that maybe someone can shed some light on. According docstring in the method process_step: I can \"dynamically alter self.form

1条回答
  •  醉梦人生
    2021-01-01 08:17

    How do you use FormWizard? If you're putting it in urls.py like docs says then it could be cached, i had that issue couple of times. Just put it in a view like:

    def my_view(request):
        return FormWizard(request)
    

    UPDATE: Example from real

    def registration_wizard(request, template_name=None):
        rw = RegistrationWizard([RegistrationForm, 0])
        #hack formwizard to replace default template
        if template_name:
            rw.get_template = lambda x: template_name
    
        return rw(request)
    

    here RegistrationWizard is a FormWizard subclass with dynamic form_list, [RegistrationForm, 0] is needed because if there's only one form at creation time, wizard won't get to form_list function. Template thing is pretty self-explanatory

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