模版中.取值
来源:7-11 机构详情展示-3
shalama
2018-10-27
course_org = CourseOrg.objects.get(id=int(org_id))
all_course = course_org.courseorg_course.all()[:4]
all_teacher = course_org.org_teacher.all()[:1]
return render(request, ‘org-detail-homepage.html’, {
‘all_course’: all_course,
‘all_teacher’: all_teacher,
‘course_org’: course_org,
在模版中
{% for teacher in CourseOrg %}
{{teacher.teacher_course.name}}
{% endfor %}
外键查询,QuerySet
是否是要遍历才能取到值
写回答
2回答
-
courses = teahcer.course_set.all()
在view中这样获取该教师的所有课程032018-11-02 -
bobby
2018-10-29
不是 也可以像操作list一样取某一个值
012018-10-29
相似问题