from functools import reduce


def getattr_orm(instance, key):
    """
    Provides a getattr method which does a recursive lookup in the orm, by splitting the key on every occurance of
    __
    :param instance:
    :param key:
    :return:
    """
    return reduce(getattr, [instance] + key.split('__'))