From 0224afcad9cf5a7ac8436ae3d68d452c7566d904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 19 Jan 2023 19:51:24 +0100 Subject: [PATCH] Don't freak out if there are no sessions --- src/timetracker/games/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/timetracker/games/views.py b/src/timetracker/games/views.py index 9274716..aa573f5 100644 --- a/src/timetracker/games/views.py +++ b/src/timetracker/games/views.py @@ -21,9 +21,15 @@ def model_counts(request): def add_session(request): context = {} + initial = {} + now = now_with_tz() + initial["timestamp_start"] = now + last = Session.objects.all().last() - initial = {"timestamp_start": now, "purchase": last.purchase} + if last != None: + initial["purchase"] = last.purchase + form = SessionForm(request.POST or None, initial=initial) if form.is_valid(): form.save()