title: How to access the checkbox data in Django form
body: <p>I have a few checkboxes in my Django form. After a user selects a particular checkbox, I want to know which all checkboxes were selected by the user. I can see the first name, last name, username, and email of the user in the Django admin, that the user provides while filling up the form, but I can't see which checkboxes did the user select.</p>
  
  <p>How can I access the Checkbox's data? I know I need to do some modifications in my code for that, so please suggest me the modifications in my code. I'm using Django 1.9.I went through some materials online and the documentation as well, but couldn't understand much. </p>
  
  <p>forms.py </p>
  
  <pre><code>from django import forms
  from django.contrib.auth.models import User
  from volunteer.models import UserProfileInfo
  
  NGO_CHOICES = (
  ('one', 'ONE'),
  ('two', 'TWO'),
  ('three', 'THREE'),)
  
  class UserForm(forms.ModelForm):
  ngo = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, 
  choices=NGO_CHOICES)
  
  class Meta():
      model = User
      fields = ('ngo','email','first_name','last_name','username')
  </code></pre>
  
  <p>views.py </p>
  
  <pre><code>from django.shortcuts import render
  from volunteer.forms import UserForm
  
  
  
  def register(request):
  
  registered = False
  
  if request.method =="POST" :
      user_form = UserForm(data=request.POST)
  
      if user_form.is_valid():
          ngo = user_form.cleaned_data['ngo'] #getting the list of the ngos. 
  
          user = user_form.save()
  
          user.save()
  
          registered = True
  
      else:
          print(user_form.errors)
  
  else:
      user_form = UserForm()
  
  return render(request, 'volunteer/volunteer.html',
                           {'user_form':user_form,
                            'registered':registered})
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  class UserProfileInfo(models.Model):
  
      user=models.OneToOneField(User)
  
      def __str__(self):
              return self.user.first_name
              return self.user.last_name
              return self.user.email
              return self.user.ngo
  </code></pre>
  
  <p>admin.py</p>
  
  <pre><code>from django.contrib import admin
  from volunteer.models import UserProfileInfo
  
  # Register your models here.
  admin.site.register(UserProfileInfo)
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.conf.urls import url
  
  from . import views
  
  app_name = 'volunteer'
  
  urlpatterns = [
  
   url(r'^', views.register, name='register'),
   ]
  </code></pre>
  
  <p>volunteer.html(which has the form)</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  
  
  &lt;meta name="viewport" content = "width=device-width, initial-scale=1.0"&gt;
  
  
  
  
  &lt;/head&gt;      
  
  &lt;body&gt;   
  
   &lt;div class="jumbotron"&gt;
      {% if registered %}
         &lt;p&gt;Thank you.&lt;p&gt;
  
      {% else %}
        &lt;h1&gt;Register yourself for Volunteering&lt;/h1&gt;
  
  
  
  
   &lt;form method="post"&gt;
      {% csrf_token %}
      {{ user_form.as_p }}
   &lt;input type="submit" name="" value="Register as a Volunteer"&gt;
  
   {% endif %}
  
   &lt;/div&gt; 
  
  
   &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;      
  </code></pre>
  
  <p>NOTE - I haven't included bootstrap, ajax and jquery libraries in the above HTML code due to formatting issues, I don't think they have anything to do with the problem, so. </p>