title: How to create and process a form with multiple same fields?
body: <p>I'm really stuck with this. To show my problem I created a new Django project and started from scratch, focusing only on one single form.</p>
  
  <p>What I'm trying to do is to create a form with several fields of the same name. I tried using <code>modelformset_factory</code> to achieve this but it looks to me like it's not what I really need.</p>
  
  <p>Below is my code (also on <a href="http://dpaste.com/836293/" rel="nofollow">dpaste</a>) which currently works fine with one single field called <code>name</code>. How can I create and process a form which would have several <code>name</code> fields? Could somebody point me in the right direction?</p>
  
  <pre><code># models.py
  class Category(models.Model):
      name = models.CharField(max_length=30, unique=True)
      user = models.ForeignKey(User, blank=True, null=True)
  
      class Meta:
          verbose_name_plural = "Ingredience Categories"
  
      def __unicode__(self):
          return self.name
  
  # forms.py
  class CategoryForm(ModelForm):
      class Meta:
          model = Category
          fields = ('name',)
  
  # views.py
  def home(request):
      if request.method == 'POST':
          catform = CategoryForm(request.POST)
          catformInstance = catform.save(commit = False)
          catformInstance.save()
          return HttpResponseRedirect('')
      else:
          catform = CategoryForm() 
  
      context = {'catform': catform}
      return render_to_response('home.html', context, context_instance=RequestContext(request))
  
  # home.html template
  &lt;h3&gt;Insert new Category&lt;/h3&gt; 
  &lt;form action="/" method="post" id="ingr-cat-form"&gt;{% csrf_token %}
  {{ catform.as_p }}
  &lt;input type="submit" name="ingrCatForm" value="Save" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong> to clarify, I want to allow user to insert several categories within one form. I think I'm getting close, here is my <strong>new version of views.py</strong> but it still stores just one category (the last one in the list):</p>
  
  <pre><code>def home(request):
      if request.method == 'POST':
          catform = CategoryForm(request.POST)
          names = request.POST.getlist('name')
          catformInstance = catform.save(commit = False)
          for name in names:
              catformInstance.name = name
              catformInstance.save()
          return HttpResponseRedirect('')
      else:
          catform = CategoryForm() 
  
      context = {'catform': catform}
      return render_to_response('home.html', context, context_instance=RequestContext(request))
  </code></pre>