Declare Instance variables in django-formtools SessionWizardView

30 views Asked by At

Using SessionWizardView, I want to declare Instance variables, that persist between steps. However, they are not persistent, when using:

def __init__(self): self.variable = {}

1

There are 1 answers

1
i-wizard On
class YourClass:
    class_variable = None

    def __init__(self):
        if YourClass.class_variable is None:
            YourClass.class_variable = "default value"
        self.instance_variable = YourClass.class_variable

instance1 = YourClass()
print("instance1>>",instance1.variable)
instance2 = YourClass()
print("instance2>>",instance2.variable)
>>> instance1>> default value
>>> instance2>> default value