diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-02 10:18:44 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 17:30:46 +0100 |
commit | 066a782e440b64f7584475347c1b762c89e0cab5 (patch) | |
tree | e5d0f38c898f24c420702682ded8d12ada2dbc3e /ishtar_common/utils.py | |
parent | e1ca97e099fab92f48471f34214bd0c5233dff5f (diff) | |
download | Ishtar-066a782e440b64f7584475347c1b762c89e0cab5.tar.bz2 Ishtar-066a782e440b64f7584475347c1b762c89e0cab5.zip |
Work on M2M historization
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 18 |
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() |