更换django自带的下载链接
1 class Case(models.Model): 2 file_type = MyFileField(verbose_name='file_obj', max_length=256, blank=True, null=True) 3 link = models.CharField(verbose_name='下载链接', max_length=64, blank=True, null=True) 4 5 def __unicode__(self): 6 return u"%s" % self.file_type.name 7 8 class MyFileField(models.FileField): 9 attr_class = MyFieldFile 10 11 class MyFieldFile(FieldFile): 12 13 def __init__(self, *args, **kwargs): 14 super(MyFieldFile, self).__init__(*args, **kwargs) 15 16 @property 17 def url(self): 18 return self.instance.link