7👍
✅
If you look at the API Documentation documentation:
Note that the content argument should be an instance of
django.core.files.File, not Python’s built-in file object. You can
construct a File from an existing Python file object like this
from django.core.files import File
# Open an existing file using Python's built-in open()
f = open('/path/to/hello.world')
myfile = File(f)
so if pdf
is a string you could use:
from django.core.files.base import ContentFile
myfile = ContentFile(pdf)
instance.structural_info.save('structure.pdf', myfile)
Source:stackexchange.com