Fixed the records pseudo property of the Transaction data model to find the records only for existing transactions, to work with Django 4.1.

This commit is contained in:
依瑪貓 2022-08-13 20:48:26 +08:00
parent 86b84bef7a
commit 4afd072cc5

View File

@ -303,8 +303,11 @@ class Transaction(DirtyFieldsMixin, StampedModel, RandomPkModel):
List[Record]: The records.
"""
if self._records is None:
self._records = list(self.record_set.all())
self._records.sort(key=lambda x: (x.is_credit, x.ord))
if self.pk is None:
self._records = []
else:
self._records = list(self.record_set.all())
self._records.sort(key=lambda x: (x.is_credit, x.ord))
return self._records
@records.setter