Updating a list within a class

77 Views Asked by At

Is it possible to update a list within a class based on instance details?

I would like to do something like this:

from formtools.wizard.views import SessionWizardView
class ContactWizard(SessionWizardView):
        form_list = [ # a list of forms used per step
            (S1, Q1),
            (S2, Q2),
            (S3, Q3),
        ]
        def form_updater(self):
            if self.get_cleaned_data_for_step("0") != None:
                form_list.append((S3, Q3),)
            return form_list

#However, I get thrown an error when I try to make the following call:
ContactWizard.form_updater(ContactWizard)
## error:
get_cleaned_data_for_step() missing 1 required positional argument: 'step'

Any help or guidance that you can provide would be VERY greatly appreciated.

1

There are 1 best solutions below

4
Lord Elrond On

It looks like you want a classmethod:

class ContactWizard(SessionWizardView):
        form_list = [ # a list of forms used per step
            (S1, Q1),
            (S2, Q2),
            (S3, Q3),
        ]
   
        @classmethod
        def form_updater(cls):
            if cls.get_cleaned_data_for_step("0") != None:
                cls.form_list.append((S3, Q3),)
            return form_list