Don't freak out if there are no sessions

This commit is contained in:
Lukáš Kucharczyk 2023-01-19 19:51:24 +01:00
parent a694406e99
commit 0224afcad9
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 7 additions and 1 deletions

View File

@ -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()