Fix keyboards and nullable fields.

This commit is contained in:
Alex Root Junior 2017-10-21 21:20:37 +03:00
parent 4bf5409295
commit f4b9bf5339
3 changed files with 14 additions and 13 deletions

View file

@ -39,7 +39,7 @@ class BaseField(metaclass=abc.ABCMeta):
:param instance:
:return:
"""
return instance.values.get(self.alias)
return instance.values.get(self.alias, self.default)
def set_value(self, instance, value, parent=None):
"""
@ -96,7 +96,10 @@ class Field(BaseField):
return value
def deserialize(self, value, parent=None):
if self.base_object is not None and not hasattr(value, 'base_object') and not hasattr(value, 'to_python'):
if isinstance(value, dict) \
and self.base_object is not None \
and not hasattr(value, 'base_object') \
and not hasattr(value, 'to_python'):
return self.base_object(conf={'parent': parent}, **value)
return value