Skip to content

Instantly share code, notes, and snippets.

@hansek
Created Mar 16, 2017
Embed
What would you like to do?
Django File mixin to automatically folderize uploaded file by app label and ID
from django.db import models
class FileAppIdFolderMixin(models.Model):
def upload_to(self, filename):
return '{app}/{id}/{filename}'.format(
app=self._meta.app_label,
id=self.id,
filename=filename
)
file = models.FileField(
upload_to=upload_to,
blank=True
)
class Meta:
abstract = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment