From 86b84bef7a69ad32c1a4b2686242a954df7c463c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 11 Aug 2022 11:48:01 +0800 Subject: [PATCH] Fixed the save() method of the Transaction data model to find the records to delete only for existing transactions, to work with Django 4.1. --- accounting/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accounting/models.py b/accounting/models.py index c0aef0b..0d891fb 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -173,7 +173,8 @@ class Transaction(DirtyFieldsMixin, StampedModel, RandomPkModel): self.ord = 1 if max_ord is None else max_ord + 1 # Collects the records to be deleted to_keep = [x.pk for x in self.records if x.pk is not None] - to_delete = [x for x in self.record_set.all() if x.pk not in to_keep] + to_delete = [] if self.pk is None \ + else [x for x in self.record_set.all() if x.pk not in to_keep] to_save = [x for x in self.records if x.is_dirty(check_relationship=True)] for record in to_save: