title: Django - Save Canvas object as a PDF-File to FileField
body: <p>(How) is it possbile to save a canvas object as a PDF-file in a FileField ?</p>
  
  <p><a href="https://docs.djangoproject.com/en/2.0/howto/outputting-pdf/#outputting-pdfs-with-django" rel="nofollow noreferrer">https://docs.djangoproject.com/en/2.0/howto/outputting-pdf/#outputting-pdfs-with-django</a></p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from django.views.generic.edit import FormView
  from reportlab.pdfgen import canvas
  
  class SomeView(FormView):
  
      form_class = SomeForm
      template_name = 'sometemplate.html'
  
  
      def form_valid(self, form):
  
          item = form.save(commit=False)
  
          # create PDF
          filename = "somefile.pdf"
          p = canvas.Canvas(filename)
          p.drawString(100, 100, "Hello world.")
          p.showPage()
          p.save()
  
          # this will not work, but i hope there is another way
          # Error: 'Canvas' object has no attribute '_committed'
          item.file = p
  
          # save form
          item.save()
  
          return super(SomeView, self).form_valid(form)
  </code></pre>
  
  <p>Traceback: (to long to paste all)</p>
  
  <pre><code>[...]
  
  Exception Type: AttributeError at /return/
  Exception Value: 'Canvas' object has no attribute '_committed'
  </code></pre>
  
  <p>If more information is need, please let me know!</p>