From 7c60ddd584ae40b5a1a1e911670b877cbd78429e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 25 Sep 2012 13:26:50 +0200 Subject: [PATCH] allow DictField to be None --- ox/django/fields.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ox/django/fields.py b/ox/django/fields.py index ce1c063..e1df5c7 100644 --- a/ox/django/fields.py +++ b/ox/django/fields.py @@ -40,6 +40,8 @@ class DictField(models.TextField): def to_python(self, value): """Convert our string value to python after we load it from the DB""" + if value == None: + return value if isinstance(value, dict): return value try: @@ -51,6 +53,8 @@ class DictField(models.TextField): def get_db_prep_save(self, value, connection): """Convert our JSON object to a string before we save""" + if value == None: + return value assert isinstance(value, dict) value = json.dumps(value, default=to_json) return super(DictField, self).get_db_prep_save(value, connection=connection)