def to_dict(self): keys = self.__mapper__.columns.keys() dict_info = {} for key in keys: if key.startswith('_'): continue value = getattr(self, key) if value is not None: if isinstance(value, datetime.datetime): value = utils.format_datetime(value) dict_info[key] = value return dict_info
def join_to_dict_recurse(self): joined = dict([(k, v) for k, v in self.__dict__.iteritems() if not k[0] == '_']) dict_info = {} for key in joined.keys(): if key.startswith('_'): continue value = getattr(self, key) if value is not None: if isinstance(value, datetime.datetime): value = utils.format_datetime(value) if isinstance(value, HelperMixin): value = value.join_to_dict_recurse() dict_info[key] = value return dict_info