from collections import OrderedDict class MultipleForms(forms.Form): """ Wraps many Form subclases in order to get a form wizard to treat them as one. Args: base_forms(list): Contains tuples with two elements each: name and class of the form we want to add. """ def set_instances(self): for name, form in self.base_forms: form_instance = form(self.data, self.files, prefix=self.prefix) self.instances_list.append(form_instance) self.instances_dict.update({name: form_instance}) def __init__(self, *args, **kwargs): for name, form in self.base_forms: self.base_fields.update(form.base_fields) super(MultipleForms, self).__init__(*args, **kwargs) self.instances_dict = OrderedDict() self.instances_list = list() if self.is_bound: self.set_instances()