2

SubTaskFormSet are my SubTasks Forms that i'm having troubles to save properly.

In html template i'm dynamically adding/removing inputs thats correspond to elements of my formset, the problem is: only the first form from de formset is being saved. This is how its being created the formset(extra=1 displays 1 input when page loads).

SubTaskFormSet = inlineformset_factory(Task, SubTask, form=SubTaskCreateForm, extra=1)

This is how im passing the formset to context dict in "get_context_data" method from TemplateView

context['form_sub_tasks'] = SubTaskFormSet(self.request.POST or None)

Saving a task form and forms of the formset:

    if all((task.is_valid(), sub_tasks.is_valid())):
        task.user = self.request.user
        task = task.save()
        sub_tasks.instance = task
        sub_tasks.save()

I noticed that when the value of this field changes, the equivalent number of forms from formset is successfully saved in database.

<input name="sub_tasks-TOTAL_FORMS" value="1" id="id_sub_tasks-TOTAL_FORMS" type="hidden">

So my question is: how can i change this TOTAL_FORMS input to be possible save more than one form from formset? Of course it could be done via javascript or manually but i'm searching for a better way to accomplish it.

Bruno Brito
  • 345
  • 4
  • 17
  • Only way I know of is through javascript like https://github.com/elo80ka/django-dynamic-formset . I ended up using a custom implementation of that since it's not super flexible. – Brian Edelman Apr 08 '18 at 20:53

0 Answers0