diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 19:23:51 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 19:23:51 +0100 | 
| commit | 6275ac4d3388f912a831c3f6178c3832ce9297b5 (patch) | |
| tree | f5d133b3456888ccd805fdf5c50b880acab3e502 /archaeological_context_records/models.py | |
| parent | d68eed24e409cf6b5c15c77fbf1034843eea9acd (diff) | |
| download | Ishtar-6275ac4d3388f912a831c3f6178c3832ce9297b5.tar.bz2 Ishtar-6275ac4d3388f912a831c3f6178c3832ce9297b5.zip  | |
Use JSON for M2M history
Diffstat (limited to 'archaeological_context_records/models.py')
| -rw-r--r-- | archaeological_context_records/models.py | 15 | 
1 files changed, 7 insertions, 8 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 030f817d9..4f1711d31 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -29,7 +29,7 @@ from django.utils.translation import ugettext_lazy as _, pgettext, \      activate, pgettext_lazy, deactivate  from django.utils.text import slugify -from ishtar_common.utils import cached_label_changed, HISTORY_M2M_SPLIT +from ishtar_common.utils import cached_label_changed  from ishtar_common.models import Document, GeneralType, \      BaseHistorizedItem, HistoricalRecords, OwnPerms, ShortMenuItem, \ @@ -84,12 +84,11 @@ class Dating(models.Model):              return unicode(self.period)          return u"%s (%s-%s)" % (self.period, start_date, end_date) -    SEP = u"$|£|$"      HISTORY_ATTR = ["period", "start_date", "end_date", "dating_type",                      "quality", "precise_dating"]      def history_compress(self): -        values = [] +        values = {}          for attr in self.HISTORY_ATTR:              val = getattr(self, attr)              if hasattr(val, 'history_compress'): @@ -100,18 +99,18 @@ class Dating(models.Model):                  val = ''              else:                  val = unicode(val) -            values.append(val) -        return self.SEP.join(values) +            values[attr] = val +        return values      @classmethod      def history_decompress(cls, full_value, create=False):          if not full_value:              return []          full_res = [] -        for value in full_value.split(HISTORY_M2M_SPLIT): +        for value in full_value:              res = {} -            for idx, val in enumerate(value.split(cls.SEP)): -                key = cls.HISTORY_ATTR[idx] +            for key in value: +                val = value[key]                  if val == '':                      val = None                  elif key in ("period", "dating_type", "quality"):  | 
