def dump_object(obj):
"""Get this object as a dict."""
def should_dump(self, attr, value):
"""Decide if the attribute should be dumped or not."""
column = self.__table__.c[attr.name]
default = column.default
if default is not None:
return not value == default.arg
elif self.__table__.c[attr.name].nullable and value is None:
return False
else:
return True
d = asdict(obj, filter=partial(should_dump, obj))
if isinstance(
obj,
db.SpacialObject
) and 'type' in d: # obj.type is not None
d['type'] = d['type'].name
return d
评论列表
文章目录