title: how can i save html checkbox value to django database
body: <p>I'm working on a subscription project that allows user select multiple services using checkbox and then calculate the total price for these services(something like selecting multiple mails from your mail account), I have these in the HTML and Js code but I wan to be able to store each selected services to the DB, please how can I archive this </p>
  
  <pre><code>&lt;form action="{% url 'sub:basic_starter' %}" id="subscription" method="post"&gt;
          {% csrf_token %}
            &lt;fieldset&gt;
              &lt;legend&gt;&lt;h5&gt;&lt;strong&gt;Business Type: &lt;/strong&gt; New Business &lt;/h5&gt; &lt;/legend&gt;
               &lt;label&gt;Brand Value Design:                       N6,180.00
                &lt;input type="checkbox" value=" 6179.50" name="services" id="bs1" onclick="subscribe())"&gt;
              &lt;/label&gt;&lt;br&gt;&lt;br&gt;
              &lt;label&gt;Business Development:                     N6,180.00
                &lt;input type="checkbox" value="6180.00" name="services" id="bs2" onclick="subscribe())"&gt;
              &lt;/label&gt;&lt;br&gt;&lt;br&gt;
              &lt;label&gt;Website Design &amp; Dev:              N6,180.00
                &lt;input type="checkbox" value=" 6180.00" name="services" id="bs3" onclick="subscribe())"&gt;
              &lt;/label&gt;&lt;br&gt;&lt;br&gt;
              &lt;label&gt;Mobile Application :          N6,180.00
                &lt;input type="checkbox" value="6180.00" name="services" id="bs4" onclick="subscribe())"&gt;
              &lt;/label&gt;&lt;br&gt;&lt;br&gt;
              &lt;label&gt;Maintenance(Host &amp; Domain):             N5,450.00
                &lt;input type="checkbox" value="5450.00" name="services" id="bs5" onclick="subscribe())"&gt;
              &lt;/label&gt;&lt;br&gt;&lt;br&gt;
              &lt;label&gt;Social Media Management:
                &lt;input type="checkbox" value="" name="services" id="bs6" onclick="subscribe())"&gt;
              &lt;/label&gt;&lt;br&gt;&lt;br&gt;
              &lt;input type="text" readonly="readonly" id="total" value="N0.00" &gt;&lt;script&gt;document.getElementById('total').innerHTML=price;&lt;/script&gt;&lt;br&gt;&lt;br&gt;
              &lt;input type="submit" value="Subscribe" class="btn btn-success"&gt;&lt;/a&gt;&lt;/button&gt;&lt;br&gt;
            &lt;/fieldset&gt;
         &lt;/form&gt;          
      &lt;/div&gt;  
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>function subscribe(){
  let input = document.getElementsByName('services'),
   total = 0.00,
   form = document.getElementById('subscription');
  for (let i = 0; i &lt; input.length; i++) {
      if(input[i].checked){
           total += parseFloat(input[i].value)
           let price = 'N' + total
      }    
  }
  document.getElementById('total').value = total.toFixed(3)
  </code></pre>
  
  <p>}
     document.getElementById('subscription').addEventListener('change', subscribe)</p>
  
  <p>Views.py</p>
  
  <pre><code>@login_required
  def subscribe(request):
      service_list = []
      if request.method == 'POST':
          sub_form = MembershipForm(request.POST)
          if sub_form.is_valid() and sub_form.cleaned_data:
              service_list.append(sub_form.data['service_name'])
              sub_form.save()
      else:
           sub_form =MembershipForm()
      return render(request, 'sub/subscribe_form.html',{'sub_form':  
      sub_form})
  </code></pre>
  
  <p>Url<code>
       path('sub', views.subscribe, name='subscribe'),</code></p>
  
  <p>Forms</p>
  
  <pre><code>class MembershipForm(forms.ModelForm):
      class Meta:
          model = Services
          fields = ('service_name', 'price',)
  </code></pre>
  
  <p>Models</p>
  
  <pre><code>class Services(models.Model):
      package_name = models.CharField(max_length=100)
      category = models.CharField(max_length=200)
      service_name = models.CharField(max_length=250)
      price = models.DecimalField(max_digits=9, decimal_places=2)
  
      def __str__(self):
          return self.service_name
  
      class Meta:
          unique_together = ('package_name', 'service_name')
  
  
  class CompanySubscription(models.Model):
      company_name = models.ForeignKey(CompanyProfile,  
       on_delete=models.CASCADE)
      services = models.ForeignKey(Services, on_delete=models.CASCADE)
      duration = models.CharField(max_length=50)
      timestamp= models.DateTimeField(auto_now=True)
  
      def __str__(self):
          return self.company_name
  </code></pre>