def apply_mine_or_others_filter(user_id, filter, queryset):
    """
    Apply the "mine" or the "others" user filters to the given queryset.
    """
    if filter == 'mine':
        return queryset.filter(user_id=user_id)

    return queryset.exclude(user_id=user_id)