how to manually assign imagefield in Django
-
03-07-2019 - |
Question
I have a model that has an ImageField. How can I manually assign an imagefile to it? I want it to treat it like any other uploaded file...
Solution
See the django docs for django.core.files.File
Where fd is an open file object:
model_instance.image_field.save('filename.jpeg', fd.read(), True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow