revsys / django-friendship

Django app to manage following and bi-directional friendships
BSD 3-Clause "New" or "Revised" License
763 stars 183 forks source link

view for remove_friend model #163

Closed R0b3rt020 closed 2 years ago

R0b3rt020 commented 2 years ago

Is there any view already made for remove_friend function in models?

frankwiles commented 2 years ago

No, I just looked through things and there isn't. I think we left that as an exercise for the user because how that might work can easily differ across projects. Maybe you can't remove friendships? Maybe the other party gets notified, maybe they don't. etc.

I wouldn't be opposed to adding a view for it if you wanted to contribute one.

R0b3rt020 commented 2 years ago

Similar to remove follow:

@login_required
def friendship_remove(
    request, friend_username, template_name="friendship/friend/remove.html"
):
    """ Remove a friend relationship """
    if request.method == "POST":
        friend_to_remove = user_model.objects.get(username=friend_username)
        friend_request = request.user
        Friend.objects.remove_friend(friend_to_remove,friend_request)
        return redirect("friendship_view_friends", request.user)

    return render(request, template_name, {"friend_username": friend_username})