From 066a782e440b64f7584475347c1b762c89e0cab5 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 2 Jan 2019 10:18:44 +0100 Subject: Work on M2M historization --- ishtar_common/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ishtar_common/utils.py') 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() -- cgit v1.2.3