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.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index ff67fc470..94e71c655 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -929,3 +929,21 @@ def get_urls_for_model(model, views, own=False, autocomplete=False,
]
return urls
+
+
+HISTORY_M2M_SPLIT = u"*||*"
+
+
+def m2m_historization_changed(sender, **kwargs):
+ obj = kwargs.get('instance', None)
+ if not obj:
+ return
+ 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
+ obj.save()