The key is that you donβt even need to use one of the subclasses of FormView to handle forms. You just need to add the equipment for processing the form manually. In case you use a subclass of FormView , it processes only 1 and only 1 form. Therefore, if you need two forms, you just need to process the second manually. I use DetailView as a base class to show that you don't even need to inherit from the FormView type.
class ManualFormView(DetailView): def get(self, request, *args, **kwargs): self.other_form = MyOtherForm() return super(ManualFormView, self).get(request, *args, **kwargs) def post(self, request, *args, **kwargs): self.other_form = MyOtherForm(request.POST) if self.other_form.is_valid(): self.other_form.save() # or whatever return HttpResponseRedirect('/some/other/view/') else: return super(ManualFormView, self).post(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(ManualFormView, self).get_context_data(**kwargs) context['other_form'] = self.other_form return context
Chris pratt
source share