Set Django’s FileField to an existing file

just set instance.field.name to the path of your file

e.g.

class Document(models.Model):
    file = FileField(upload_to=get_document_path)
    description = CharField(max_length=100)


doc = Document()
doc.file.name="path/to/file"  # must be relative to MEDIA_ROOT
doc.file
<FieldFile: path/to/file>

Leave a Comment