From 560fac7bdb68364567c7e4a3f9d30403b2ff8bb4 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 28 Aug 2013 13:45:23 -0400 Subject: [PATCH] change file upload directory structure --- karmaworld/apps/notes/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index b23bdcb..b8ce9ce 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -26,6 +26,15 @@ except: fs = FileSystemStorage(location=settings.MEDIA_ROOT) +def _choose_upload_to(instance, filename): + # /school/course/year/month/day + return u"{school}/{course}/{year}/{month}/{day}".format( + school=instance.course.school.slug, + course=instance.course.slug, + year=instance.uploaded_at.year, + month=instance.uploaded_at.month, + day=instance.uploaded_at.day) + class Document(models.Model): """ An Abstract Base Class representing a document intended to be subclassed @@ -47,7 +56,7 @@ class Document(models.Model): is_hidden = models.BooleanField(default=False) fp_file = django_filepicker.models.FPFileField( - upload_to='queue/%Y/%m/%j/', + upload_to=_choose_upload_to, null=True, blank=True, help_text=u"An uploaded file reference from Filepicker.io") @@ -55,7 +64,6 @@ class Document(models.Model): abstract = True ordering = ['-uploaded_at'] - def __unicode__(self): return u"Document: {1} -- {2}".format(self.name, self.uploaded_at) -- 2.25.1