标签:
def get_file_path(instance, filename): return ‘file/document/%s/%s/%s‘ % (instance.period.code, instance.student.college.code, filename) class Document(models.Model): title = models.CharField(max_length=50, blank=True, verbose_name="文档名", default="") student = models.ForeignKey(‘accounts.Student‘, verbose_name="学生") period = models.ForeignKey(‘systemconfig.Periods‘, verbose_name="阶段") file = models.FileField(upload_to=get_file_path, verbose_name="文档", blank=True, null=True) mark = models.SmallIntegerField(null=True, blank=True, verbose_name="标记") create_time = models.DateTimeField(verbose_name="添加时间", auto_now_add=True) class Meta: verbose_name = "学生报告文档" verbose_name_plural = "学生报告文档"
重点就是get_file_path
def get_file_path(instance, filename):
return ‘file/document/%s/%s/%s‘ % (instance.period.code, instance.student.college.code, filename)
class Document(models.Model):
title = models.CharField(max_length=50, blank=True, verbose_name="文档名", default="")
student = models.ForeignKey(‘accounts.Student‘, verbose_name="学生")
period = models.ForeignKey(‘systemconfig.Periods‘, verbose_name="阶段")
file = models.FileField(upload_to=get_file_path, verbose_name="文档", blank=True, null=True)
mark = models.SmallIntegerField(null=True, blank=True, verbose_name="标记")
create_time = models.DateTimeField(verbose_name="添加时间", auto_now_add=True)
class Meta:
verbose_name = "学生报告文档"
verbose_name_plural = "学生报告文档"
django FileFIeld和ImageField 上传路径改写
标签:
原文地址:http://www.cnblogs.com/tuifeideyouran/p/4384522.html