Skip to content

Instantly share code, notes, and snippets.

@sthzg
Last active August 29, 2015 14:18
Show Gist options
  • Save sthzg/f328da3da4cb8bc814cd to your computer and use it in GitHub Desktop.
Save sthzg/f328da3da4cb8bc814cd to your computer and use it in GitHub Desktop.
Dynamically change storage location for Django's FileField and ImageField.
from django.core.files.storage import FileSystemStorage
def MyModel(models.Model):
# ... model stuff ...
some_file = models.FileField(
storage=FileSystemStorage(
location='/my/private/path/'
),
upload_to='downloads'
)
# files will be at /my/private/path/downloads/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment