Django File mixin to automatically folderize uploaded file by app label and ID
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 | |
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