Fix checking duration when database is empty
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Lukáš Kucharczyk 2023-01-05 16:33:32 +01:00
parent 34ce1e9b05
commit 85f52fc735
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 8 additions and 4 deletions

View File

@ -103,9 +103,13 @@ def add_platform(request):
def index(request):
context = {}
result = Session.objects.all().aggregate(Sum("duration_calculated"))
context["total_duration"] = format_duration(
result["duration_calculated__sum"], "%H hours %m minutes"
)
if Session.objects.count() == 0:
duration_value = 0
else:
result = Session.objects.all().aggregate(Sum("duration_calculated"))
context["total_duration"] = format_duration(
result["duration_calculated__sum"], "%H hours %m minutes"
)
context["total_duration"] = duration_value
context["title"] = "Index"
return render(request, "index.html", context)