class ActualForm(forms.Form): """ This form's fields are the sum of the fields defined by its parent forms. By creating this form dynamically I'm able to take advantage of the ModelForms functionality of automatically setting the Model's fields while still ending up with a form that comprises multiple models. The Parent forms are specified in the :attr: parent_forms or received in the constructor as :arg: parent_forms """ parent_forms = [SomeForm1, SomeForm2] def __init__(self, parent_forms=[], *args, **kwargs): super(ActualForm, self).__init__(*args, **kwargs) # If the class was instantiated with a list of parent Forms as # an argument, use said list. Else look for a hard-coded attribute. # This line is hilarious. parent_forms = parent_forms if parent_forms else self.parent_forms # Make a list of form fields. The list comprehension makes a # nested list that gets flattened by itertools' chain form_values = list(itertools.chain( *[form().fields.iteritems() for form in parent_forms] )) # Add the values of the parent forms to the actual form for k, v in form_values: self.fields[k] = v # In Views: class ActualFormView(FormView): """ Use the Class Based View as always, but make sure to set form_class to be the dynamic Form. """ form_class = ActualForm def form_valid(self, form): # Create objects. Do stuff. return super(ActualFormView, self).form_valid(form)