title: Django Dynamic name attribute and getting values in views.py
body: <p>I have created a form using a TemplateView in Django, and I have had to use a lot of JavaScript to make the form generation dynamic.  What I did is make it so the user can add multiple software packages with associated information by clicking an <code>Add More Software</code> button and then a new id and name attribute is generated for that form-group for each input, for example:</p>
  
  <pre><code>&lt;input id="software-name-1" name="software-name-1" type="text"&gt;
  </code></pre>
  
  <p>And when an add software button is clicked, a have a piece of JavaScript that clones and adds the form-groups that are identical to the form, but then sets the id and name to <code>software-name-2</code>.  I also have it so you can delete the form group.  But right now, if a form group is deleted, other groups after it could still have id's of <code>software-name-3</code> while <code>software-name-2</code> could no longer exist because it was deleted before the <code>submit</code> button was pressed.  So when the form POST's I could have <code>software-name-1</code>, the <code>software-name-3</code> after that.  </p>
  
  <p>What is the best way to get and use that data in the views.py?  I tried doing a count in the format of <code>for software_name in request.POST['software-name-' + str(count)]:</code> but of course this does not work if <code>software-name-[whatever the number]</code> is skipped.  </p>
  
  <p>Here is my jQuery code for changing ID's and name attributes: </p>
  
  <pre><code>$(document).on('click', '#add-software-btn:last', function() {
      // Find last software container
      var $div = $('div[id^="software-container"]:last');
      console.log($div);
      //counter
      var num = parseInt($div.prop("id").match(/\d+/g), 10) + 1;
      // Clone the original software container inside the click function
      var $software_container_copy = $software_container_original_copy.clone(true)
          .prop('id', 'software-container-' + num);
  
      // Rename form id, for and name attributes
      $software_container_copy.find('label[for^="software-name"]:last')
          .attr('for', 'software-name-' + num);
      $software_container_copy.find('input[id^="software-name"]:last')
          .attr('id', 'software-name-' + num)
          .attr('name', 'software-name-' + num);
  });
  </code></pre>
  
  <p>Again, the user has the option of deleting software they added before posting the form, so this can mess up the order of the name's that Django uses in the view.  What is the best approach for getting this data in the views.py?  There are other input values besides software names, so keeping each set up values specific to the software that the user adds is critical, so that is why I have to have unique names and ID's generated instead of just going through a list.  I am putting all this data in a JSON file. Maybe this can be can be done first with JavaScript, and sent as an object under one software-name to the views.  The main issue with this is I can't use a count, but I must search for all POST data that contains `software-name-' and use it with the data that falls under it. I don't know.  Any ideas?</p>