From 6aec1430efbebb126c4ffedd8f3b1a633724e1aa Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 18 Oct 2017 10:43:55 +0200 Subject: Json field: fix pre_save in order to initialize json with an empty dict (refs #3077) --- archaeological_finds/models_treatments.py | 1 + ishtar_common/models.py | 6 +++++- ishtar_common/wizards.py | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index b4d98528b..03eeed452 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -225,6 +225,7 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, return values def pre_save(self): + super(Treatment, self).pre_save() # is not new if self.pk is not None: return diff --git a/ishtar_common/models.py b/ishtar_common/models.py index becb37516..6a59adb77 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -953,11 +953,15 @@ class JsonDataField(models.Model): class JsonData(models.Model): - data = JSONField(default={}, db_index=True) + data = JSONField(default={}, db_index=True, blank=True) class Meta: abstract = True + def pre_save(self): + if not self.data: + self.data = {} + class Imported(models.Model): imports = models.ManyToManyField( diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 701f6eca3..f86e03df0 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -737,6 +737,9 @@ class Wizard(NamedUrlWizardView): if has_problemetic_null: continue + if hasattr(model, 'data') and 'data' not in value: + value['data'] = {} + if get_or_create: value, created = model.objects.get_or_create( **value) -- cgit v1.2.3