title: How to save form input in database for multiple inputs at the same time in Django?
body: <p>I am learning django and am creating an application that can register the students in a particular class based on their name and registration number. So, I created an application where the user can add form elements from where the user can add options to add different students directly into the form at the same time. Thus, the user can decide the number of student he wants to add at the same time, and add the students by their name and registration number. I have created the following form:</p>
  
  <pre><code>    &lt;form method="post" action="/add_rules/"&gt;
          {% csrf_token %}
          &lt;div class="field_wrapper"&gt;
              &lt;div&gt;
                  &lt;label&gt;Enter Name&lt;/label&gt;
                  &lt;input type="text" name="personname"&gt;
                  &lt;label&gt;Enter registration number&lt;/label&gt;
                  &lt;input type="text" name="personregnumber"&gt;
                  &lt;a href="javascript:void(0)" class="addPerson"&gt;Add&lt;/a&gt;
                  &lt;br&gt;&lt;br&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;button type="submit"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>The corresponding javascript  to add and remove the input fields is:</p>
  
  <pre><code>$(document).ready(function () {
          var addButton = $('.addPerson');
          var wrapper = $('.field_wrapper');
          var field_html = '&lt;div&gt;&lt;label&gt;Enter name&lt;/label&gt;&lt;input type="text" name="personname"&gt;&lt;label&gt;Enter registration number&lt;/label&gt;&lt;input type="text" name="personregnumber"&gt;&lt;a href="javascript:void(0)" class="remove_button"&gt;Remove&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;'
  
          $(addButton).click(function() {
              $(wrapper).append(field_html);
          })
          $(wrapper).on('click', '.remove_button', function(e) {
              e.preventDefault();
              $(this).parent('div').remove();
          })
      })
  </code></pre>
  
  <p>I am stuck at how to add multiple student data fields to the data base at the same time? It will be great if someone could help. </p>
  
  <p>It is clear when I have to add data from the form into the database one at a time, I can do that by the following code:</p>
  
  <p>view.py:</p>
  
  <pre><code>    def add_student(request):
          personname = request.POST["personname"]
          personregnumber = request.POST["personregnumber"]
  
          given_student = Student(personname=personname,personregnumber=personregnumber)
          given_student.save()
          return render(request, 'student/studentregistered.html')
  </code></pre>
  
  <p>where the models.py is:</p>
  
  <pre><code>    class Student(models.Model):
          personname = models.CharField(max_length=100)
          personregnumber = models.CharField(max_length=100)
  
          def __str__(self):
              return self.personname
  </code></pre>
  
  <p>As you can see above the code works perfectly to add the student details one at a time, but when I click add so as to add multiple students at the same time, the above code fails. Can anyone tell me how can I save multiple students at the sametime in the database?</p>