From 228fc2bf5f6542de2dc14fc74c0bc995210b3a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 4 Oct 2024 10:17:38 +0200 Subject: [PATCH] avoid exception on game overview when sessions are 0 --- games/views/game.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/games/views/game.py b/games/views/game.py index 0f358fe..9e8401e 100644 --- a/games/views/game.py +++ b/games/views/game.py @@ -273,7 +273,9 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse: sessions_all = Session.objects.filter(purchase__edition__game=game).order_by( "-timestamp_start" ) - last_session = sessions_all.latest() + last_session = None + if sessions_all.exists(): + last_session = sessions_all.latest() session_count = sessions_all.count() session_paginator = Paginator(sessions_all, 5) page_number = request.GET.get("page", 1) @@ -310,7 +312,9 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse: ) ], ), - ), + ) + if last_session + else "", ], ), "columns": ["Edition", "Date", "Duration", "Actions"],