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/models.py | |
parent | be8538ec1cf68dc5dcffa927558181b2e7e6225e (diff) | |
download | Ishtar-35f9cbb4d247efe038bbc3507bd8c8c056735ca8.tar.bz2 Ishtar-35f9cbb4d247efe038bbc3507bd8c8c056735ca8.zip |
Work on M2M historization
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e1318ef62..2915c4997 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -69,7 +69,7 @@ from ishtar_common.models_imports import ImporterModel, ImporterType, \ Import, TargetKeyGroup from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug, \ get_all_field_names, merge_tsvectors, cached_label_changed, \ - generate_relation_graph + generate_relation_graph, HISTORY_M2M_SPLIT __all__ = [ 'ImporterModel', 'ImporterType', 'ImporterDefault', 'ImporterDefaultValues', @@ -507,6 +507,21 @@ class GeneralType(Cached, models.Model): def natural_key(self): return (self.txt_idx,) + def history_compress(self): + return self.txt_idx + + @classmethod + def history_decompress(cls, value=""): + if not value: + value = "" + res = [] + for txt_idx in value.split(HISTORY_M2M_SPLIT): + try: + res.append(cls.objects.get(txt_idx=txt_idx)) + except cls.DoesNotExist: + continue + return res + @property def explicit_label(self): return u"{} ({})".format(self.label, self._meta.verbose_name) @@ -1433,6 +1448,8 @@ class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData, IS_BASKET = False EXTERNAL_ID_KEY = '' EXTERNAL_ID_DEPENDENCIES = [] + HISTORICAL_M2M = [] + history_modifier = models.ForeignKey( User, related_name='+', on_delete=models.SET_NULL, verbose_name=_(u"Last editor"), blank=True, null=True) |