I
I
IVBAN2018-10-01 12:15:05
Django
IVBAN, 2018-10-01 12:15:05

How to save a file in a model field if the file is already in a Django project?

After creating the file with the python-docx library, I want to save it to the model object.

document.save('isaus/files/media/documents/'+my_doc_name + '.doc')

f = open('isaus/files/media/documents/'+my_doc_name + '.doc', 'rb')
today = datetime.now().date()

mydoc = Document(name=f.name, file=f, data=today)
mydoc.save()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question