from django.core.exceptions import ObjectDoesNotExist

def get_onetoone_or_none(obj, attr):
    """ Instead of letting django throw and exception, return None when a OneToOneField is null """
    try:
        return getattr(obj, attr)
    except ObjectDoesNotExist:
        return None