models.py:
class TrainerProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE,
null=True, related_name='trainer_profile')
profile_picture = models.ImageField(blank=True)
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone
number must be entered in the format: '+999999999'. Up to 15 digits
allowed.")
mobile_number = models.CharField(validators=[phone_regex],
max_length=17, blank=True)
location = models.CharField(max_length=200,null=True,blank=True)
gender = models.CharField(choices=GENDER_CHOICES,max_length=150,
blank=True)
cv = models.FileField(blank=True)
approval=models.BooleanField(default=False)
def __str__(self):
return self.user.username
在我的模板中:
<li class="list-group-item">
<b>Download CV</b> <a class="pull-right">{{ trainer.cv }}</a>
</li>
在TrainerProfileModel中,我有一个名为cv的文件字段。我想允许用户单击链接时直接下载文件。有什么方法可以实现?