Created
August 23, 2012 19:32
-
-
Save abrookins/3440646 to your computer and use it in GitHub Desktop.
Set the path of an ImageField in Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Thank you!