def find_attribute(obj, value):
    """
    Finds the attribute connected to the last object when a chain of
    connected objects is given in a string separated with double underscores.
    For example when a model x has a foreign key to model y and model y has
    attribute a, findattr(x, 'y__a') will return the a attribute from the y
    model that exists in x.
    """
    if "__" in value:
        value_list = value.split("__")
        attr = get_attribute(obj, value_list[0])
        return find_attribute(attr, "__".join(value_list[1:]))
    return get_attribute(obj, value)