title: Django - Boolean Fields on Checkbox Input
body: <p>I have a ModelForm which has Boolean Field and CheckboxInput. The Boolean field provides values of 0 (False) &amp; 1 (True) by default in the MYSQL Database.</p>
  <p>The form is a modal and uses JSON to output the content from the Model. When the JSON file adds the content it enters either True or False.</p>
  <p>The issue occurs when I try to change and submit the value of the Checkbox Input from False to True. When I try this I get the following message:</p>
  <p><a href="https://i.stack.imgur.com/DU2Es.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DU2Es.png" alt="enter image description here" /></a></p>
  <p>Oddly this works the other way around and allows me to submit the change from True to False.</p>
  <p>Below is the code (I have only included the field with the issue.) The field is First_Time_Booking</p>
  <p>Model.</p>
  <pre><code>first_time_booking = models.BooleanField()
  </code></pre>
  <p>Form Widget.</p>
  <pre><code>'first_time_booking': CheckboxInput(attrs={'class': 'form-check-input', 'id': 'bfbw_edit_first_time_booking', 'name': 'bfbw_edit_first_time_booking'}),
  </code></pre>
  <p>View</p>
  <pre><code>def update_bfbw(request):
      if request.method == 'POST':
          bfbw_booking_id = request.POST.get('bfbw_booking_ref')
          bfbw_data = BFBWBookings.objects.get(id=bfbw_booking_id)
          bfbw_data.school_name = request.POST['school_name']
          bfbw_data.first_time_booking = request.POST.get('first_time_booking', False)
          bfbw_data.save()
      else:
          print(form.errors)
      return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
  </code></pre>
  <p>I have tried writing an If function to alter the value, this then works to change the value to On but not when switching it off. I then get the below message.</p>
  <pre><code>if request.POST['first_time_booking'] == 'on':
              bfbw_data.first_time_booking = True
          else:
              bfbw_data.first_time_booking = False
  </code></pre>
  <p><a href="https://i.stack.imgur.com/s5mkQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s5mkQ.png" alt="enter image description here" /></a></p>
  <p>Any help on this will be great. Thanks in advance for any replies.</p>