Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set the path of an ImageField in Django
from django.db import models
# Assuming this model.
class Example(models.Model):
image = models.ImageField(upload_to="somewhere/special")
# You want to set this field to point to an existing image (in a script, or a view, etc.).
example = Example.objects.get(id=1)
# You must use a path relative to the settings.MEDIA_ROOT.
example.image = 'somewhere/special/filename.jpeg'
example.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.