由于出现索引超出数据库错误,导致出现索引超出范围错误。我怎么能引用它作为占位符只是空白。 这是我的view.py:
class ProjectView(ListView):
template_name = 'project_portal/home.html'
queryset = Project.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['project'] = Project.objects.all()
context['impact_scenario'] = Update.objects.filter(project_id=2).filter(category=1).latest('update')
context['support_model'] = Update.objects.filter(project_id=2).filter(category=2)[0]
context['monitoring_status'] = Update.objects.filter(project_id=2).filter(category=3)[0]
context['training'] = Update.objects.filter(project_id=2).filter(category=4)[0]
context['service_rehearsal'] = Update.objects.filter(project_id=2).filter(category=5)[0]
context['other_update'] = Update.objects.filter(project_id=2).filter(category=6)[0]
return context
这些类别中的每一个都从数据库中提取数据,但是某些字段最初将为空白。在模型中,将null和blank设置为null,我希望这样做就足够了。我也尝试过使用:
context['other_update'] = Update.objects.filter(project_id=2).filter(category=6).latest('update')
希望可以解决问题,但事实并非如此。请问如何在视图中允许空白数据?