allow DictField to be None
This commit is contained in:
parent
8f82cefa78
commit
7c60ddd584
1 changed files with 4 additions and 0 deletions
|
@ -40,6 +40,8 @@ class DictField(models.TextField):
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
"""Convert our string value to python after we load it from the DB"""
|
"""Convert our string value to python after we load it from the DB"""
|
||||||
|
if value == None:
|
||||||
|
return value
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
|
@ -51,6 +53,8 @@ class DictField(models.TextField):
|
||||||
|
|
||||||
def get_db_prep_save(self, value, connection):
|
def get_db_prep_save(self, value, connection):
|
||||||
"""Convert our JSON object to a string before we save"""
|
"""Convert our JSON object to a string before we save"""
|
||||||
|
if value == None:
|
||||||
|
return value
|
||||||
assert isinstance(value, dict)
|
assert isinstance(value, dict)
|
||||||
value = json.dumps(value, default=to_json)
|
value = json.dumps(value, default=to_json)
|
||||||
return super(DictField, self).get_db_prep_save(value, connection=connection)
|
return super(DictField, self).get_db_prep_save(value, connection=connection)
|
||||||
|
|
Loading…
Reference in a new issue