def get_object_or_none(klass, *args, **kwargs):
    """
    Runs klass.objects.get with the given arguments and returns None if no
    matching object is found.
    """
    try:
        return klass.objects.get(*args, **kwargs)
    except (klass.DoesNotExist, klass.MultipleObjectsReturned):
        return None