diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-18 10:43:55 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-18 10:43:55 +0200 |
commit | 5afa971792019e16bb067f9020011788587572d8 (patch) | |
tree | e495edf504e1c5aa0b7a992930593afbbd5b9833 /ishtar_common | |
parent | 1bd278fb83d40fcc8f5392320a3238cdad5b8416 (diff) | |
download | Ishtar-5afa971792019e16bb067f9020011788587572d8.tar.bz2 Ishtar-5afa971792019e16bb067f9020011788587572d8.zip |
Json field: fix pre_save in order to initialize json with an empty dict (refs #3077)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 6 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 3 |
2 files changed, 8 insertions, 1 deletions
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) |