码迷,mamicode.com
首页 > Web开发 > 详细

django FileFIeld和ImageField 上传路径改写

时间:2015-04-01 19:23:17      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!