Bridge between two users

12 views
Skip to first unread message

Soumen Khatua

unread,
Jun 9, 2020, 6:34:05 AM6/9/20
to django...@googlegroups.com
Hi Folks,

I have one Follower system and here I want to check  those are following to me,   we have a mutual connection or not. If they are following to me and I'm not following to them, I want to set in frontend follow back. Inside the views I'm fetching the data and sending them to serializer but I don't ,How I can check it?
My models and views are in below:

models.py
-----------------
class Follow(models.Model):
    follower = models.ForeignKey(User,on_delete = models.CASCADE,related_name = 'following')
    followee = models.ForeignKey(User,on_delete = models.CASCADE,related_name = 'followers')
    created_at = models.DateTimeField(auto_now_add = True, null = True)
    updated_at = models.DateTimeField(auto_now = True, null = True)
    class Meta:
       unique_together = ("follower", "followee")
       ordering  = ('-created_at',)


views.py:
-------------------
class FollowerAPIView(APIView,PaginationHandlerMixin):
    pagination_class = BasicPagination
    serializer_class = UserFollowerSerializer
    def get(self,request,*args,**kwargs):
        follower_qs = Follow.objects.filter(followee = request.user).select_related('follower')
        page = self.paginate_queryset(follower_qs)
        if page is not None:
            serializer = self.get_paginated_response(self.serializer_class(page, many=True).data)
        else:
            serializer = self.serializer_class(follower_qs, many=True)
        return Response(serializer.data,status=status.HTTP_200_OK)


Please help me 

Thank You

Regards,
Soumen
Reply all
Reply to author
Forward
0 new messages