1. 后台models.py代码
class CourseResource(BaseModel):
course = models.ForeignKey(Course, on_delete=models.CASCADE, verbose_name="课程")
name = models.CharField(max_length=100, verbose_name="资源名")
file = models.FileField(max_length=200, upload_to="course/resource/%Y/%m", verbose_name="下载地址")
class Meta:
verbose_name = "课程资源"
verbose_name_plural = verbose_name
def __str__(self):
return self.name
2. 前端Html代码
<div class="box mb40">
<h4>资料下载</h4>
<ul class="downlist">
{% for resource in course_resource %}
<li>
<span><i class="aui-iconfont aui-icon-file"></i> {{ resource.name }}</span>
<a href="{{ MEDIA_URL }}{{ resource.file }}" class="downcode" target="_blank" download="" data-id="274" title="">下载</a>
</li>
{% endfor %}
</ul>
</div>