summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-11 14:01:02 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-11 17:30:46 +0100
commitd68eed24e409cf6b5c15c77fbf1034843eea9acd (patch)
tree53a7b08c771d8b454fe83b4b7fc40f7ca5b62277 /ishtar_common/utils.py
parentf0f17e614d03140fef0b1dff3aca8fdb9e06aded (diff)
downloadIshtar-d68eed24e409cf6b5c15c77fbf1034843eea9acd.tar.bz2
Ishtar-d68eed24e409cf6b5c15c77fbf1034843eea9acd.zip
Fix history M2M save
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 94e71c655..56c6f669f 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -938,12 +938,22 @@ def m2m_historization_changed(sender, **kwargs):
obj = kwargs.get('instance', None)
if not obj:
return
+ hist_values = {}
for attr in obj.HISTORICAL_M2M:
values = []
for value in getattr(obj, attr).all():
if not hasattr(value, "history_compress"):
continue
values.append(value.history_compress())
- setattr(obj, 'historical_' + attr, HISTORY_M2M_SPLIT.join(values))
- obj.skip_history_when_saving = True
+ hist_values['historical_' + attr] = HISTORY_M2M_SPLIT.join(values)
+ for key in hist_values:
+ setattr(obj, key, hist_values[key])
+ # force resave of last history record
+ if hasattr(obj, 'skip_history_when_saving'):
+ delattr(obj, 'skip_history_when_saving')
+ obj._force_history = True
+ q = obj.history.order_by("-history_date")
+ if q.count():
+ last = q.all()[0]
+ last.delete()
obj.save()