def _object_lookup_to_pk(model, lookup):
    """Performs a lookup if `lookup` is not simply a primary key otherwise is
    returned directly."""
    try:
        pk = int(lookup)
    except (TypeError, ValueError):
    # otherwise, attempt a lookup
        try:
            pk = model._default_manager.get(**lookup).pk
        except model.DoesNotExist:
            pk = None
    return pk