def get_field_with_path(model, name):
    """
        Resolve property by name and figure out its join path.

        Join path might contain both properties and tables.
    """
    path = []

    # For strings, resolve path
    if isinstance(name, string_types):
        # create a copy to keep original model as `model`
        current_model = model

        for attribute in name.split('.'):
            value = getattr(current_model, attribute)

            if (hasattr(value, 'property') and
                    hasattr(value.property, 'direction')):
                current_model = value.property.mapper.class_

                table = current_model.__table__

                if need_join(model, table):
                    path.append(value)

            attr = value
    else:
        attr = name

        # Determine joins if table.column (relation object) is provided
        if isinstance(attr, InstrumentedAttribute):
            columns = get_columns_for_field(attr)

            if len(columns) > 1:
                raise Exception('Can only handle one column for %s' % name)

            column = columns[0]

            # TODO: Use SQLAlchemy "path-finder" to find exact join path to the target property
            if need_join(model, column.table):
                path.append(column.table)

    return attr, path
dataset/ETHPy150Open flask-admin/flask-admin/flask_admin/contrib/sqla/tools.py/get_field_with_path/original