Skip to content

Instantly share code, notes, and snippets.

@hseritt
Created February 25, 2017 12:46
Show Gist options
  • Save hseritt/a0cf76e3dbe555939851c02ddccaf978 to your computer and use it in GitHub Desktop.
Save hseritt/a0cf76e3dbe555939851c02ddccaf978 to your computer and use it in GitHub Desktop.
Django model class using upload directories with a date/time structure hierarchy
...
class ArticleAttachment(models.Model):
"""
Attached files for articles
"""
att_file = models.FileField(
upload_to='content/uploads/articles/%Y/%m/%d/%H/%M/%S')
class Meta:
verbose_name = 'Article Attachment'
verbose_name_plural = 'Article Attachments'
def __str__(self):
return os.path.basename(self.att_file.name)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment