def toggle_follow(request, username):
    """
    Either follow or unfollow a user.
    """
    other_user = get_object_or_404(User, username=username)
    if request.user == other_user:
        is_me = True
    else:
        is_me = False
    if request.user.is_authenticated() and request.method == "POST" and not is_me:
        if request.POST["action"] == "follow":
            Following.objects.follow(request.user, other_user)
            request.user.message_set.create(message=_("You are now following %(other_user)s") % {'other_user': other_user})
            if notification:
                notification.send([other_user], "tweet_follow", {"user": request.user})
        elif request.POST["action"] == "unfollow":
            Following.objects.unfollow(request.user, other_user)
            request.user.message_set.create(message=_("You have stopped following %(other_user)s") % {'other_user': other_user})
    return HttpResponseRedirect(reverse("profile_detail", args=[other_user]))
dataset/ETHPy150Open skabber/django-microblogging/microblogging/views.py/toggle_follow/original