add exception

This commit is contained in:
2022-10-21 07:54:57 +00:00
parent 8dfa69cf8d
commit 6d72c7a2d3

View File

@@ -4,6 +4,7 @@ from collections import deque
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, UpdateView
@@ -121,7 +122,10 @@ class TaskDetailView(LoginRequiredMixin, DetailView):
docus = Document.objects.filter(task__id=self.object.id).order_by("-date") docus = Document.objects.filter(task__id=self.object.id).order_by("-date")
context["documents"] = docus context["documents"] = docus
try:
context["topic"] = Topic.objects.get(task_list=self.object.task_list) context["topic"] = Topic.objects.get(task_list=self.object.task_list)
except ObjectDoesNotExist:
context["topic"] = None
return context return context