From ee8dbba2bfe3b281de4535b5b41239a1ce6a1702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oktay=20=C3=96zel?= Date: Tue, 19 Nov 2024 16:07:43 +0300 Subject: [PATCH] Update follow_unfollow.py --- backend/app/views_directory/follow_unfollow.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/app/views_directory/follow_unfollow.py b/backend/app/views_directory/follow_unfollow.py index 02c5887f..29840ec5 100644 --- a/backend/app/views_directory/follow_unfollow.py +++ b/backend/app/views_directory/follow_unfollow.py @@ -1,6 +1,6 @@ from django.shortcuts import get_object_or_404 from django.http import JsonResponse -from app.models import Profile +from app.models import Profile, ActivityStream from rest_framework.decorators import api_view, permission_classes from rest_framework.permissions import IsAuthenticated @@ -13,6 +13,15 @@ def follow_user(request): if user_to_follow != current_user_profile: current_user_profile.following.add(user_to_follow) + + ActivityStream.objects.create( + actor=request.user, + verb="followed", + object_type="Profile", + object_id=user_to_follow.user.id, + target=None # Optional: could be used for specific contexts + ) + return JsonResponse({"message": "Followed successfully"}, status=200) return JsonResponse({"error": "Cannot follow yourself"}, status=400)