Fix bugs with snapshots: opening earliest snapshot, deleting latest

This commit is contained in:
Edgar P. Burkhart 2022-05-22 10:39:29 +02:00
parent 57ace376d8
commit 02b0fae3f7
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 7 additions and 4 deletions

View file

@ -121,7 +121,7 @@ class Snapshot(models.Model):
try: try:
_next = self.__class__.objects.get(previous=self) _next = self.__class__.objects.get(previous=self)
except self.__class__.DoesNotExist: except self.__class__.DoesNotExist:
pass super().delete(*args, **kwargs)
else: else:
_next.previous = self.previous _next.previous = self.previous
super().delete(*args, **kwargs) super().delete(*args, **kwargs)

View file

@ -123,6 +123,9 @@ def snapshot(request, date=None):
_transactions = None _transactions = None
else: else:
_snapshot = get_object_or_404(Snapshot, date=date) _snapshot = get_object_or_404(Snapshot, date=date)
if _snapshot.previous is None:
_transactions = None
else:
_transactions = Transaction.objects.filter( _transactions = Transaction.objects.filter(
date__lt=_snapshot.date, date__gte=_snapshot.previous.date date__lt=_snapshot.date, date__gte=_snapshot.previous.date
) )