FormSet saves the data of only one form
<p>When I submitted forms (but on page I filled id more than 1 form) - my FormSet saves the data of only one form, the rest of the data just disappear...</p>

<p>My template:</p>

<pre><code> &lt;div id="data"&gt;
    &lt;form method="post" action="/lookup/" id="test_data"&gt;{% csrf_token %}
    {{ formset.management_form }}
        {% for form in formset %}
            &lt;section id="test_data_row"&gt;
            {{ form }}
            &lt;/section&gt;
        {% endfor %}
    &lt;/form&gt;
&lt;/div&gt;
&lt;div class="bt"&gt;
    &lt;button type="submit" class="btn btn-default" id="submit_form" form="test_data"&gt;Submit&lt;/button&gt;
    &lt;button type="button" class="btn btn-default" id="add" value="Add row"/&gt;Add row&lt;/button&gt;
&lt;/div&gt;
</code></pre>

<p>My forms.py:</p>

<pre><code>class LookupForm(forms.ModelForm):
   class Meta:
      model = look
      exclude = ()
LookupFormSet = formset_factory(LookupForm, can_delete=True)
</code></pre>

<p>My model</p>

<pre><code>class look(models.Model):
    class Meta():
        db_table = 'lookup'
    id_device = models.CharField(max_length=75)
    phone_number = models.CharField(max_length=100)
    phone_number_country = models.CharField(max_length=1000)
    text = models.CharField(max_length=1000, default=None)
</code></pre>

<p>my views.py:</p>

<pre><code>def manage_articles(request):
   LookupFormSet = modelformset_factory(model=look, exclude=())
   if request.method == "POST":
      formset = LookupFormSet(
         request.POST, request.FILES,
         queryset=look.objects.none(),
      )
      if formset.is_valid():
         for form in formset:
             form.save()
      return HttpResponseRedirect('/')
   else:
      formset = LookupFormSet(queryset=look.objects.none())
   return render(request, 'req/lookup.html', {'formset': formset})
</code></pre>

<p>my JS (js for add new form):</p>

<pre><code>document.getElementById('add').onclick = duplicate;
var i = 0;
var original = document.getElementById('test_data');
function duplicate() {
   var clone = original.cloneNode(true); // "deep" clone
   clone.id = "test_data" + ++i; // there can only be one element with an ID
   original.parentNode.appendChild(clone);
}
</code></pre>

<p>You cannot save a formset as it contains multiple forms. So I would suggest you change your code to:</p>

<pre><code>   if formset.is_valid():
       for form in formset:
            form.save()
       return HttpResponseRedirect('/')
</code></pre>

<p>See the <a href="https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#module-django.forms.formsets" rel="nofollow">docs</a>.</p>

python django django-forms