title: Django formset only adding one form
body: <p>OK, so this is my first time using formsets. I am trying to create a table that I can dynamically add rows to and fill out each row, then submit and have Django put them all in the database. Every time I submit it only adds the first form.</p>
  
  <h3>File views.py:</h3>
  
  <pre><code>@main_context_wrapper
  def bacteriaForm2(request,context):
  if not request.user.is_authenticated():
      #If user isn't authenticated, then just redirect to login
      return HttpResponseRedirect('/login/')
  BacteriaFormSet = formset_factory(BacteriaForm)
  if request.POST:
      bacteriaformset = BacteriaFormSet(request.POST, request.FILES)
      if bacteriaformset.is_valid():
          context["error"] = ""
          for form in bacteriaformset:
              form.save()
          return HttpResponseRedirect('/')
      else:
          context["error"] = "validation"
          context["bacteriaformset"] = BacteriaFormSet
  
      context.update(csrf(request))
      return render_to_response('bacteriaForm.html', context)
  
  else:
      #The request was a GET, add the form to the context
      context["bacteriaformset"] = BacteriaFormSet()
  
  #Add all siteInfo objects to allow for dynamic site info drop down menus
  siteInfo = SiteInfo.objects.all()
  context["siteInfo"] = siteInfo
  return render(request, "bacteriaForm.html", context)
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>{% extends "inherited/main.html" %}
  
  {% block content %}
  &lt;h1&gt; Bacteria Entry Form &lt;/h1&gt;
  
  &lt;form action='/bacteriaForm/' method="post"&gt;{% csrf_token %}
      {{bacteriaformset.management_form}}
  
      {% if error == "validation" %}
      &lt;div class="alert alert-danger"&gt;
          &lt;p&gt;
              &lt;strong&gt;Error: &lt;/strong&gt;Form not completed properly.
          &lt;/p&gt;
      &lt;/div&gt;
      {% endif %}
  
      &lt;table id="id_forms_table"&gt;
          &lt;tr&gt;
              {% for field in bacteriaformset.forms.0 %}
                  {% if not field.is_hidden %}
                       &lt;th&gt;{{ field.label }}&lt;/th&gt;
                  {% endif %}
              {% endfor %}
          &lt;/tr&gt;
          {% for f in bacteriaformset.management_form %}
              {{ f }}
          {% endfor %}
          {% for f in bacteriaformset.forms %}
              &lt;tr id="{{ f.prefix }}-row" class="dynamic-form"&gt;
              {% for field in f %}
                  {% if not field.is_hidden %}
                       &lt;td&gt;
                       {{ field.errors }}
                       {{ field }}
                       &lt;/td&gt;
                  {% else %}
                       &lt;td valign="bottom"&gt;{{ field }}&lt;/
                  {% endif %}
              {% endfor %}
              &lt;td{% if forloop.first %} class="hidden"{% endif %}&gt;
                        &lt;a id="remove-{{ form.prefix }}-row" href="javascript:void(0)"                           class="delete-row"&gt;delete&lt;/a&gt;
              &lt;/td&gt;
              &lt;/tr&gt;
          {% endfor %}
          &lt;tr&gt;
              &lt;td colspan="4"&gt;&lt;a href="javascript:void(0)" class="add-row"&gt;add            property&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
      &lt;/table&gt;
      &lt;div&gt;
          &lt;input type="submit" value="submit" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
      $(function () {
          $('.add-row').click(function() {
              return addForm(this, 'form');
          });
          $('.delete-row').click(function() {
              return deleteForm(this, 'form');
          });
      });
  
      function updateElementIndex(el, prefix, ndx) {
          var id_regex = new RegExp('(' + prefix + '-\\d+)');
          var replacement = prefix + '-' + ndx;
          if ($(el).attr("for")) $(el).attr("for", $(el).attr("for").replace(id_regex,      replacement));
          if (el.id) el.id = el.id.replace(id_regex, replacement);
          if (el.name) el.name = el.name.replace(id_regex, replacement);
      }
  
      function addForm(btn, prefix) {
          var formCount = parseInt($('#id_' + prefix + '-TOTAL_FORMS').val());
          var row = $('.dynamic-form:first').clone(true).get(0);
          $(row).removeAttr('id').insertAfter($('.dynamic-    form:last')).children('.hidden').removeClass('hidden');
          $(row).children().not(':last').children().each(function() {
              updateElementIndex(this, prefix, formCount);
              $(this).val('');
          });
          $(row).find('.delete-row').click(function() {
              deleteForm(this, prefix);
          });
          $('#id_' + prefix + '-TOTAL_FORMS').val(formCount + 1);
          return false;
      }
  
      function deleteForm(btn, prefix) {
          $(btn).parents('.dynamic-form').remove();
          var forms = $('.dynamic-form');
          $('#id_' + prefix + '-TOTAL_FORMS').val(forms.length);
          for (var i=0, formCount=forms.length; i&lt;formCount; i++) {
              $(forms.get(i)).children().not(':last').children().each(function() {
                  updateElementIndex(this, prefix, i);
              });
          }
          return false;
      }
      $("#id_date").datepicker();
  &lt;/script&gt;
  {% endblock %}
  </code></pre>
  
  <h3>File Models.py</h3>
  
  <pre><code>class BacteriaEntry(models.Model):
  """
  A bacteria entry contains information about a test set's
  bacteria levels at a specific time. BacteriaEntry utilizes the
  Djano model.
  """
  siteNumber = models.IntegerField()
  date = models.DateField()
  sampleNumber = models.IntegerField(primary_key=True)
  ecoliRawCount = models.IntegerField(null=True)
  ecoli = models.DecimalField(decimal_places=10, max_digits=20, null=True)
  ecoliException = models.IntegerField(null=True)
  coliformRawCount = models.IntegerField(null=True)
  coliform = models.DecimalField(decimal_places=10, max_digits=20, null=True)
  coliformException = models.IntegerField(null=True)
  comments = models.CharField(max_length=2000, null=True)
  
  """Returns the sample number of the Bacteria Entry"""
  def __unicode__(self):
      return smart_unicode(self.sampleNumber)
  </code></pre>
  
  <p>Here is some post data</p>
  
  <pre><code>&lt;QueryDict: {u'form-0-date': [u'02/24/2014'], u'form-0-comments': [u'65'], u'form- MAX_NUM_FORMS': [u'1000', u'1000'], u'form-0-coliformRawCount': [u'5'],
   u'form-0-coliform': [u'65'], u'form-0-ecoliException': [u'56'], u'form-TOTAL_FORMS':   [u'1', u'1'], u'form-0-sampleNumber': [u'1554'], u'form-0-ecoliRawC
   ount': [u'35'], u'form-0-coliformException': [u'56'], u'form-INITIAL_FORMS': [u'0',   u'0'], u'csrfmiddlewaretoken': [u'VSnaJCW6R9z8iEKib46cHuBJ6AKTPPUT'],
   u'form-0-ecoli': [u'51'], u'form-0-siteNumber': [u'100']}&gt;
  </code></pre>
  
  <p>I'm not exactly sure where my problem is. I have spent a lot of time trying to figure this out. I am not sure what is wrong.</p>