根据http://blog.csdn.net/cendywang/article/details/17587849,http://gwmwhu.iteye.com/blog/1453827后得到自己的例子(想创建路径为‘excel/2015/001/filename’)
例子:models.py
def get_path(self,filename):
time = 'excel/%Y/'
return datetime.now().selftime(str(time))+self.proj_num+'/'+filename
datetime.now().strftime(str(time)显示时间(此例只显示年份,%Y为年份格式)
class project(models.Model):
#fields
proj_num = models.CharField('编号',max_length = 50,null = False,blank = False,unique = True)
excel_path = models.FileField(upload_to = get_path)
#...
def __unicode__(self):
return ...
class Meta: