title: how to get the value of checked radio button using django and jquery
body: <p>i have a simple form that includes <strong>text fields</strong> and <strong>radio buttons</strong>
   where the system take the user input  and add new record to the database.</p>
  
  <p>the problem that once the user fill the form and click on <strong>submit button</strong> the system display the below error:</p>
  
  <blockquote>
    <p>return Database.Cursor.execute(self, query, params)
    django.db.utils.IntegrityError: NOT NULL constraint failed:
    map_person.gender</p>
  </blockquote>
  
  <h1>models.py</h1>
  
  <pre><code>class Person(models.Model):
      boolChoice = (
          ("M","Male"),("F","Female")
          )
  
      name = models.CharField(max_length=50)
      date = models.DateField()
      description = models.TextField()
      gender = models.CharField(max_length=10, choices= boolChoice)
  
          def __str__(self):
              return str(self.name)
  </code></pre>
  
  <h1>addPerson.html</h1>
  
  <pre><code>{% extends 'base.html' %}
  
  {% block content %}
  
  &lt;div class="hero__content"&gt;
     &lt;form method="POST" class="form-style-9"&gt;{% csrf_token %}
          {{ form.as_p }}
  
  
  &lt;ul&gt;
  
      &lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
  &lt;li&gt;
  
      &lt;h2&gt;Add Member&lt;/h2&gt;
  
  &lt;/li&gt;
  
  &lt;li&gt;
      &lt;input type="text" name="name" class="field-style field-split align-right" placeholder= "enter ur name " id="name"/&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;input type="date" name="date" class="field-style field-full align-none" placeholder= " your birthdate" id="birthdate" /&gt;
  
  &lt;/li&gt;
  &lt;li&gt;
      &lt;input type="radio" name="gender"  value="male"&gt; Male&lt;br&gt;
      &lt;input type="radio" name="gender"  value="female"&gt; Female&lt;br&gt;
  
  &lt;/li&gt;
  
  &lt;li&gt;
  &lt;textarea name="description" class="field-style" placeholder= "introduce yourself " id="description"&gt;&lt;/textarea&gt;
  &lt;/li&gt;
  
  &lt;li&gt;
  &lt;input type="submit" class="field-style field-full align-none" id="save" value="ADD" /&gt;
      &lt;script type="text/javascript"&gt;
                   $(function(){
                      $('#save').on('click',function(e){
                          e.preventDefault()
                          name=$('#name').val()
                          birthdate=$('#birthdate').val()
                          description=$('#description').val()
                          radioValue = $("input[name = 'gender']:checked").val()
                          if (radioValue){
                              alert("radioValue =", radioValue)
                          }
                          alert("name =", name)
                          alert("date =", birthdate)
                          alert("desc =", description)
       $.ajax({
        url:'/addperson/',
        method:'POST',
        data: {
  
                  na:name,
                  bi:birthdate,
                  de:description,
                  ra:radioValue
        },
        headers:{
         'X-CSRFToken':'{{csrf_token}}'
        }
       }).done(function(msg) {
                          document.location = "/home.html"
                          alert('ﻟﻘﺪ ﺗﻢّ ﺣﻔﻆ اﻟﻤﻌﻠﻮﻣﺎﺕ')
  
  
       }).fail(function(err){
        alert('ﻟﻢ ﻳﺘﻢ اﻟﺤﻔﻆ')
       })
      })
     })
    &lt;/script&gt;
  &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/form&gt;
  
    &lt;/div&gt;
  
  
  {% endblock %}
  </code></pre>
  
  <h1>views.py</h1>
  
  <pre><code>def addperson(request):
      print("request method = " , request.method)
      if request.method == "POST":
          name = request.POST['na']
          birthdate = request.POST['bi']
          description=request.POST['de']
          radiovalue=request.POST['ra']
  
          person=Person.objects.create(
              name=name,
              date=birthdate,
              description=description
              )
          person.save()
  
          return render(request,'./home.html')
      else:
          print("this is a get METHOD")
  </code></pre>