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...
Asked
Active
Viewed 6,310 times
1 Answers
20
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)

null
- 878
- 6
- 11
-
If you have to manually temper with files, for example you download an image, this extension may come handy: http://stackoverflow.com/a/19476403/635636 – kecske Jul 17 '14 at 22:29
-
model_instance.image_field.save('filename.jpeg',
, True) worked for me – Jisson May 20 '20 at 11:12