def dynamic_upload_to self filename folder_name file datetime datetime

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def dynamic_upload_to(self, filename):
folder_name = 'file/%s/%s' % (datetime.datetime.now().strftime("%Y/%m/%d"), self.sub_matter.pk)
file_name = os.path.normpath(get_valid_filename(os.path.basename(filename)))
return os.path.join(folder_name, file_name)
@python_2_unicode_compatible
class File(NotificationObjectMixin, MPTTModel, SubMatterRelatedModelMixin, TimeStampedModel):
LOCAL = 'lc'
user = models.ForeignKey('users.User', related_name='folders', null=True, blank=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
name = models.CharField(max_length=255, null=True, blank=False)
is_dir = models.BooleanField(default=True)
#File's fileds
token = models.ForeignKey('Token', related_name='folders', null=True, blank=True)
type = models.CharField(max_length=2, choices=deepcopy(TYPE_CHOICES).append((LOCAL, _('Local'))), default=LOCAL)
file = models.FileField(max_length=255, upload_to=dynamic_upload_to, null=True, blank=True)
backend_id = models.CharField(max_length=1024, null=True, blank=True)
mime_type = models.CharField(max_length=255, default='pekama/directory', blank=True)
size = models.CharField(max_length=125, default='0', blank=True)