Jack Ha
Jack Ha

Reputation: 20951

how to manually assign imagefield in Django

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

Upvotes: 20

Views: 6763

Answers (1)

null
null

Reputation: 898

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)

Upvotes: 21

Related Questions