def recursive_getattr(obj, attr):
    """Does the same as the builtin getattr function, but works with multiple sub-attributes.

    So, for example:

    getattr(obj, 'attribute')

    works fine, but

    getattr(obj, 'attribute.anotherattribute')

    doesn't. This fixes that. Use in exactly the same way as getattr.
    """
    prev_part = obj

    for part in attr.split("."):
        prev_part = getattr(prev_part, part)

    return prev_part