From 94c84d9b36ee0a3c217c441383f2f320d27a9548 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 1 Mar 2019 17:45:23 +0100 Subject: [PATCH] Update dirtydelta to handle None --- utils/dirty.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/utils/dirty.py b/utils/dirty.py index 96ad0c94..6b78604e 100644 --- a/utils/dirty.py +++ b/utils/dirty.py @@ -16,8 +16,20 @@ class Dirty: class DirtyDelta(Dirty): @property def delta(self): - return self.value - self.initial_value + if self.initial_value is None: + initial_value = 0 + else: + initial_value = self.initial_value + if self.value is None: + value = 0 + else: + value = self.value + return value - initial_value @delta.setter def delta(self, value): - self.value = self.initial_value + value + if self.initial_value is None: + initial_value = 0 + else: + initial_value = self.initial_value + self.value = initial_value + value