title: Django Form error: expected string or bytes-like object for datetime object?
body: <p>I have a very simple django form for renting out keys that defaults a due date for the user, the user can change the date and then go on and save the form. However whenever I save the <code>key_instance</code>, django throws a <code>error: expected string or bytes-like object</code>. I know the datetime object is causing this error because if i comment it out everything works fine. Here is my views.py and forms.py</p>
  
  <p>forms.py: </p>
  
  <pre><code>class UpdateKeyRequestForm(forms.Form):
  
      APPROVE_CHOICES = [
          ('d', 'Deny this key request'),
          ('a', 'Approve this key request')
  
      ]
  
      request_status = forms.CharField(label='Please select to accept or deny this request.',widget=forms.Select(choices=APPROVE_CHOICES))
  
      due_date = forms.DateField(help_text='Enter a date (YYYY-MM-DD) between now and 4 weeks (default 3). ')
  
      def clean_due_date(self):
          due_date = self.cleaned_data['due_date']
          approved_status = self.cleaned_data['request_status']
  
          # Check date is not in past.
          if due_date &lt; datetime.date.today():
              raise ValidationError(_('Invalid date - renewal in past'))
          if due_date &gt; datetime.date.today() + datetime.timedelta(weeks=4):
              raise ValidationError(_('Invalid date - renewal more than 4 weeks ahead'))
  
  
          return due_date, approved_status
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>@permission_required('catalog.can_mark_returned')
  def update_key_request(request, pk):
      """
      View function for renewing a specific keyInstance by admin
      """
      key_inst=get_object_or_404(KeyInstance, pk=pk)
  
  
      # If this is a POST request then process the Form data
      if request.method == 'POST':
  
          # Create a form instance and populate it with data from the request (binding):
          form = UpdateKeyRequestForm(request.POST)
  
          # Check if the form is valid:
          if form.is_valid():
              # process the data in form.cleaned_data as required (here we just write it to the model due_back field)
              request_status = form.cleaned_data['request_status']
              due_date = form.cleaned_data['due_date']
              if request_status == 'a':
                  key_inst.due_back = due_date
                  key_inst.status = 'o'
                  key_inst.date_out = datetime.date.today()
                  key_inst.save()
              else:
                  key_inst.status = 'a'
                  key_inst.save()
  
              # redirect to a new URL:
              return HttpResponseRedirect(reverse('all-available-keys'))
      else:
          default_due_date = datetime.date.today() + datetime.timedelta(weeks=3)
          form = UpdateKeyRequestForm(initial={'due_date': default_due_date})
  
      #If this is a GET (or any other method) create the default form.
  
      return render(request, 'catalog/roomkey_request_update.html', {'form': form, 'keyinst': key_inst})
  </code></pre>
  
  <p>But the thing is I implemented this exact logic with the exact same method to update the due date and it's still working fine. I am very confused as to why this one throws an error. Can anyone please shed some light? </p>
  
  <p>Here is my local var on the error page:</p>
  
  <pre><code>due_date    
  (datetime.date(2018, 6, 13),)
  form    
  &lt;UpdateKeyRequestForm bound=True, valid=True, fields=(due_date)&gt;
  key_inst    
  &lt;KeyInstance: Conestogo River (3fc9458a-5ec8-46a3-a04e-6a48e650b15f)&gt;
  pk  
  UUID('3fc9458a-5ec8-46a3-a04e-6a48e650b15f')
  request 
  &lt;WSGIRequest: POST '/catalog/key/3fc9458a-5ec8-46a3-a04e-6a48e650b15f/update'&gt;
  </code></pre>