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 | 35f9cbb4d247efe038bbc3507bd8c8c056735ca8 (patch) | |
tree | e5d0f38c898f24c420702682ded8d12ada2dbc3e /ishtar_common/utils.py | |
parent | be8538ec1cf68dc5dcffa927558181b2e7e6225e (diff) | |
download | Ishtar-35f9cbb4d247efe038bbc3507bd8c8c056735ca8.tar.bz2 Ishtar-35f9cbb4d247efe038bbc3507bd8c8c056735ca8.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() |