summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index e293562ff..ba77a07e4 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -943,13 +943,17 @@ def m2m_historization_changed(sender, **kwargs):
continue
values.append(value.history_compress())
hist_values[attr] = values
- # force resave of last history record
- if hasattr(obj, 'skip_history_when_saving'):
- delattr(obj, 'skip_history_when_saving')
obj.history_m2m = hist_values
- obj._force_history = True
- q = obj.history.order_by("-history_date")
- if q.count():
- last = q.all()[0]
- last.delete()
+ if getattr(obj, 'skip_history_when_saving', False):
+ # assume the last modifier is good...
+ q = obj.history.filter(
+ history_modifier_id=obj.history_modifier_id,
+ ).order_by('-history_date', '-history_id')
+ hist = q.all()[0]
+ hist.history_m2m = hist_values
+ hist.history_date = hist.last_modified = datetime.datetime.now()
+ hist.save()
+ obj.skip_history_when_saving = True
+ elif not obj.history_modifier:
+ obj.skip_history_when_saving = True
obj.save()