Like getattr(obj, field_name) only follows model relationships through "__" or "." as link separators

    >>> from django.contrib.auth.models import Permission
    >>> import math
    >>> p = Permission.objects.all()[0]
    >>> follow_double_underscores(p, 'content_type__name') == p.content_type.name
    True
    >>> follow_double_underscores(p, 'math.sqrt(len(obj.content_type.name))', eval_python=True) == math.sqrt(len(p.content_type.name))
    True

def follow_double_underscores(obj, field_name=None, excel_dialect=True, eval_python=False, index_error_value=None):
    '''Like getattr(obj, field_name) only follows model relationships through "__" or "." as link separators

    >>> from django.contrib.auth.models import Permission
    >>> import math
    >>> p = Permission.objects.all()[0]
    >>> follow_double_underscores(p, 'content_type__name') == p.content_type.name
    True
    >>> follow_double_underscores(p, 'math.sqrt(len(obj.content_type.name))', eval_python=True) == math.sqrt(len(p.content_type.name))
    True
    '''
    if not obj:
        return obj
    if isinstance(field_name, list):
        split_fields = field_name
    else:
        split_fields = re_model_instance_dot.split(field_name)
    if False and eval_python:
        try:
            return eval(field_name, {'datetime': datetime, 'math': math, 'collections': collections}, {'obj': obj})
        except IndexError:
            return index_error_value
        except:
            pass

    if len(split_fields) <= 1:
        if hasattr(obj, split_fields[0]):
            value = getattr(obj, split_fields[0])
        elif hasattr(obj, split_fields[0] + '_id'):
            value = getattr(obj, split_fields[0] + '_id')
        elif hasattr(obj, split_fields[0] + '_set'):
            value = getattr(obj, split_fields[0] + '_set')
        elif split_fields[0] in obj.__dict__:
            value = obj.__dict__.get(split_fields[0])
        elif eval_python:
			value = eval('obj.' + split_fields[0])
        else:
            return follow_double_underscores(getattr(obj, split_fields[0]), field_name=split_fields[1:], eval_python=eval_python, index_error_value=index_error_value)
        if value and excel_dialect and isinstance(value, datetime.datetime):
            value = value.strftime('%Y-%m-%d %H:%M:%S')
        return value
    return follow_double_underscores(getattr(obj, split_fields[0]), field_name=split_fields[1:], eval_python=eval_python, index_error_value=index_error_value)