for name, relation in list(mapper.relationships.items()):
    if relation not in found:
        found.add(relation)
related_obj = getattr(obj, name)
if related_obj is not None:
    if relation.uselist:
        out[name] = [object_to_dict(child, found) for child in related_obj]
else:
    out[name] = object_to_dict(related_obj, found)
return out
Преобразовать результат формы SqlAlchemy в dict