Skip to content Skip to sidebar Skip to footer

FormView CBV Change ModelForm Per Request

I am trying to build a Wizard for populating data in to DataBase. I try the session.Wizard with out success plus I don't think this is what ti need. correct me if I am wrong. so ba

Solution 1:

found an answer from another post that is working by combining 2 people answer Switch case for form_class and template_name

@Denny Crane

class Foo(FormView):
    def dispatch(self, request, *args, **kwargs):
        self.var = request.session['sessionvar']['var']
        if self.var == some_value:
            form_class = form1
            template_name = template1
        elif self.var == another_value:
            form_class = form2
            template_name = template2
        [...]
        return super(Foo, self).dispatch(request, *args, **kwargs)

@Serafeim

need to override get_form_class() as well

def get_form_class(self):
    self.form_class = FORM[self.step]
    return self.form_class

Post a Comment for "FormView CBV Change ModelForm Per Request"