From f6c1beb824be07283bad824e75ceb71c0d13ef8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 12 Aug 2020 13:52:44 +0800 Subject: [PATCH] Revised the is_dirty method of the transaction data model in the accounting application. --- accounting/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/accounting/models.py b/accounting/models.py index 4b49785..a99c160 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -170,7 +170,7 @@ class Transaction(DirtyFieldsMixin, models.Model): return reverse( "accounting:transactions.detail", args=("transfer", self)) - def is_dirty(self, **kwargs): + def is_dirty(self, check_relationship=False, check_m2m=None): """Returns whether the data of this transaction is changed and need to be saved into the database. @@ -178,9 +178,13 @@ class Transaction(DirtyFieldsMixin, models.Model): bool: True if the data of this transaction is changed and need to be saved into the database, or False otherwise. """ - if super(Transaction, self).is_dirty(**kwargs): + if super(Transaction, self).is_dirty( + check_relationship=check_relationship, + check_m2m=check_m2m): return True - if len([x for x in self.records if x.is_dirty(**kwargs)]) > 0: + if len([x for x in self.records + if x.is_dirty(check_relationship=check_relationship, + check_m2m=check_m2m)]) > 0: return True kept = [x.pk for x in self.records] if len([x for x in self.record_set.all() if x.pk not in kept]) > 0: