From 35f9cbb4d247efe038bbc3507bd8c8c056735ca8 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/models.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'ishtar_common/models.py') 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) -- cgit v1.2.3