django class based view multiple form validatiton
<p>I'm currently trying to have <b>two</b> forms on a single page. I'm using Class Based Views.</p>

<pre><code>class TaskDetailView(FormMixin, generic.DetailView):
    model = Task
    template_name="tasks/detail.html"
    form_class = NoteForm
    form_class2 = DurationForm

    def get_context_data(self, **kwargs):
        context = super(TaskDetailView, self).get_context_data(**kwargs)
        context['note_form'] = self.get_form()
        context['notes'] = Note.objects.filter(task__slug=self.kwargs['slug'])
        context['duration_form'] = self.form_class2()
        context['duration'] = Duration.objects.all()
        return context

    def get_success_url(self):
       return reverse('task_detail', kwargs={'slug': self.kwargs['slug']})

    def post(self, request, *args, **kwargs):
        if not request.user.is_authenticated: 
            return HttpResponseForbidden
        self.object = self.get_object()
        form = self.get_form()
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

    def form_valid(self, form):
        current_task = get_object_or_404(Task, slug=self.kwargs['slug'])
        self.object = form.save(commit=False)
        self.object.task =  current_task
        self.object.save()
        return HttpResponse(self.get_success_url())
</code></pre>

<p>My current status is that I'm able to display all the forms and save ONLY the Notes form. I'm not able to save the Duration Form despite there's a 200 status POST, the data is not being saved to the database.</p>

<p>I think my mistake is that I'm not validating it but I'm really not sure how to, and there isn't much information on multiple forms on CBVs in Django.</p>

<p>I would really appreciate some guidance and assistance.</p>

<p>Thanks</p>

<p>Your <code>post</code> method doesn't do anything with the second form. You'd need to instantiate it and check its validity as you do with the first one.</p>

python django forms