【发布时间】:2020-03-23 09:57:53
【问题描述】:
这是我的意见.py
@login_required
def appsc(request):
allapplied = Applied_Scholarships.objects.filter(user_id = request.user.id)
for applied in allapplied.iterator():
print('hi')
sch_id = applied.scholarship_id
queryset = ScholarshipDetails.objects.filter(id = sch_id)
print(queryset)
context = {"object_list":queryset}
return render(request,'applied-scholarships.html',context)
在这里,我需要查看一个学生的申请奖学金。因此,我已经过滤了 Applied_Scholarship 表中的条目。现在,我获取了 scholarship_id 并过滤了 ScholarshipDetails 表中的条目,以便获得奖学金的名称和其他详细信息。
现在如何防止 object_list 被覆盖? 这段代码给我的价值只有 1 个奖学金而不是 2 个。
这是我的模板:
<table class="table mb-0">
<tr>
<th>Scholarship name</th>
<th>End Date</th>
<th>Status</th>
<th></th>
<th></th>
</tr>
{% for instance in object_list %}
<tr>
<td>{{instance.name}}</td>
<td>{{instance.end_date}}</td>
<td>{{applied.status}}</td>
<td><a href = "government/home">{{schdets.link}}</a></td>
</tr>
{% endfor %}
</table>
我需要使用列表吗? 如果是,那么如何?
【问题讨论】: