In my Django app, I have a PDF in bytes:
JavaScript
x
3
1
print(myPDF)
2
> b'%PDF-1.3n1 0 objn<<n/Type /Pagesn/Count 2....
3
I want to save it in my database:
JavaScript
1
3
1
obj.document = myPDF
2
obj.save()
3
However I keep getting an 'bytes' object has no attribute '_committed'
error on save.
Advertisement
Answer
The answer was a built-in Django function, ContentFile.
JavaScript
1
6
1
from django.core.files.base import ContentFile
2
3
4
obj.document = ContentFile(myPDF, '........pdf')
5
obj.save()
6