def METHOD_NAME(logged_in_user):
    public = Q(is_public=True)
    if logged_in_user is not None and not logged_in_user.is_anonymous():
        private_with_access = Q(instanceuser__user=logged_in_user)
        instance_filter = public | private_with_access
    else:
        instance_filter = public
    return instance_filter