implemented follow notifications with profile redirection

This commit is contained in:
nvrl committed 2026-02-19 15:47:54 +01:00
1 parent e86baaddb7
commit 68a9e71d04
5 files changed
+48 -17

No files matched your search

+1
View File
@@ -128,6 +128,7 @@ class Notification(models.Model):
TYPE_CHOICES = [
('reply', 'Reply'),
('mention', 'Mention'),
('follow', 'Follow'),
('ticket_new', 'New Ticket'),
('ticket_reply', 'Ticket Reply'),
('profile_comment', 'Profile Comment'),
+10 -1
View File
@@ -553,7 +553,16 @@ class UserViewSet(viewsets.ModelViewSet):
user_to_follow = self.get_object()
if user_to_follow == request.user:
return Response({'error': 'You cannot follow yourself'}, status=status.HTTP_400_BAD_REQUEST)
request.user.following.add(user_to_follow)
if not request.user.following.filter(pk=user_to_follow.pk).exists():
request.user.following.add(user_to_follow)
# Notify the user being followed
Notification.objects.create(
recipient=user_to_follow,
actor=request.user,
notification_type='follow'
)
return Response({'status': 'followed'})
@action(detail=True, methods=['post'], permission_classes=[permissions.IsAuthenticated])