Don't raise exception if ListField/DictField are stored as None

This commit is contained in:
Thomas Steinacher 2013-06-17 06:35:52 -07:00
commit 17a1844b6f

View file

@ -527,7 +527,7 @@ class ListField(ComplexBaseField):
def to_python(self, val):
to_python = getattr(self.field, 'to_python', None)
return [to_python(v) for v in val] if to_python else val
return [to_python(v) for v in val] if to_python and val else val or None
def to_mongo(self, val):
to_mongo = getattr(self.field, 'to_mongo', None)
@ -615,7 +615,7 @@ class DictField(ComplexBaseField):
def to_python(self, val):
to_python = getattr(self.field, 'to_python', None)
return {k: to_python(v) for k, v in val.iteritems()} if to_python else val
return {k: to_python(v) for k, v in val.iteritems()} if to_python and val else val or None
def value_for_instance(self, value, instance, name=None):
name = name or self.name