From 13e607f9a7754eaf3f4ceb86b96c84f5fb02823e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= <lukas@kucharczyk.xyz>
Date: Wed, 27 Nov 2024 18:35:44 +0100
Subject: [PATCH] Add error handling if no Sessions exist

---
 games/views/session.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/games/views/session.py b/games/views/session.py
index 0acd412..0c38eb3 100644
--- a/games/views/session.py
+++ b/games/views/session.py
@@ -47,7 +47,10 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
             | Q(device__name__icontains=search_string)
             | Q(device__type__icontains=search_string)
         )
-    last_session = sessions.latest()
+    try:
+        last_session = sessions.latest()
+    except Session.DoesNotExist:
+        last_session = None
     page_obj = None
     if int(limit) != 0:
         paginator = Paginator(sessions, limit)
@@ -109,7 +112,9 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
                                         )
                                     ],
                                 ),
-                            ),
+                            )
+                            if last_session
+                            else "",
                         ]
                     ),
                 ],