Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to manually assign imagefield in Django

Tags:

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...

like image 397
Jack Ha Avatar asked May 01 '09 12:05

Jack Ha


1 Answers

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)
like image 118
null Avatar answered Sep 18 '22 08:09

null