N
N
NyxDeveloper2021-09-21 16:49:18
Django
NyxDeveloper, 2021-09-21 16:49:18

How to create a new object with a FileField field, in which to insert a file already on the server?

I'm trying to write a file on the server to a database object. The fact is that if I specify it via with open, then a new file is created in the wrong directory, next to the existing one and random characters at the end. How to specify a file that exists on the server so that it is created in the folder you need, which is given by the function from upload_to?

with open(myfile_path), "rb") as file:
    Document.objects.create(file=File(file))

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