From 02b0fae3f7099a08ec2c6c795e07471931c6a76f Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 22 May 2022 10:39:29 +0200 Subject: [PATCH] Fix bugs with snapshots: opening earliest snapshot, deleting latest --- nummi/main/models.py | 2 +- nummi/main/views.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nummi/main/models.py b/nummi/main/models.py index c12dca4..e9dd980 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -121,7 +121,7 @@ class Snapshot(models.Model): try: _next = self.__class__.objects.get(previous=self) except self.__class__.DoesNotExist: - pass + super().delete(*args, **kwargs) else: _next.previous = self.previous super().delete(*args, **kwargs) diff --git a/nummi/main/views.py b/nummi/main/views.py index 724a404..4a200fa 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -123,9 +123,12 @@ def snapshot(request, date=None): _transactions = None else: _snapshot = get_object_or_404(Snapshot, date=date) - _transactions = Transaction.objects.filter( - date__lt=_snapshot.date, date__gte=_snapshot.previous.date - ) + if _snapshot.previous is None: + _transactions = None + else: + _transactions = Transaction.objects.filter( + date__lt=_snapshot.date, date__gte=_snapshot.previous.date + ) return render( request, "main/snapshot.html",