<ul>
{% regroup lectures by get_lecture_category_display as category_list %}
<h3>Lectures</h3>
<ul>
{% for category in category_list %}
<strong>
<li>{{ category.grouper }}</li>
</strong>
<ul>
{% for c in category.list %}
.............
<li>{{ c.lecture_title }}</li>
<li>{{ c.content }}</li>
{% for file in files %}
{% if file.files %}
<li><a href='{{ MEDIA_URL }}{{ file.files.url }}'>download</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
{% endfor %}
</ul>
</ul>
返回def courses(request, slug):
query = Course.objects.get(slug=slug)
context = {'courses': Course.objects.filter(slug=slug),
'lectures': query.lectures.order_by('lecture_category'),
'files': FileUpload.objects.all(),
}
return render(request, 'courses/courses.html', context)
,但struct没有预加载的关联。
我是否被迫选择查询来预加载它的关联?或者我可以以某种方式避免无用的查询?