change file upload directory structure
authorSeth Woodworth <seth@sethish.com>
Wed, 28 Aug 2013 17:45:23 +0000 (13:45 -0400)
committerSeth Woodworth <seth@sethish.com>
Wed, 28 Aug 2013 17:45:23 +0000 (13:45 -0400)
karmaworld/apps/notes/models.py

index b23bdcbcf5d4db492c4130ce0e74ef09c5a66763..b8ce9ce5d01d853b66f9aeb0babe43b84cb03d1a 100644 (file)
@@ -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)