def model_tree(name, model_cls, visited=None):
if not visited:<EOL><INDENT>visited = set()<EOL><DEDENT>visited.add(model_cls)<EOL>mapper = class_mapper(model_cls)<EOL>columns = [column.key for column in mapper.column_attrs]<EOL>related = [model_tree(rel.key, rel.mapper.entity, visited)<EOL>for rel in mapper.relationships if rel.mapper.entity not in visited]<EOL>return {name: columns + related}<EOL>
Create a simple tree of model's properties and its related models.

    It traverse trough relations, but ignore any loops.

    :param name: name of the model
    :type name: str
    :param model_cls: model class
    :param visited: set of visited models
    :type visited: list or None
    :return: a dictionary where values are lists of string or other \
    dictionaries