1
File()
is only a wrapper around Python’s file object. It won’t work with strings like your generated PDF. For that, you need the ContentFile class. Try:
(...)
djangofile = ContentFile(pdf_file)
invoice.pdf = djangofile
invoice.pdf.name = "myfilename.pdf"
invoice.save()
Source:stackexchange.com