Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RatingCount(APIView):
- object = None
- def post(self, request): # Getting rating count for Post or Comment object
- content_type = request.data.get("content_type")
- object_id = request.data.get("object_id")
- if content_type == "post":
- self.object = Post.objects.get(id=object_id)
- elif content_type == "comment":
- self.object = Comment.objects.get(id=object_id)
- rating_count = LikeDislike.objects.filter(
- content_type=ContentType.objects.get_for_model(self.object), object_id=self.object.id).aggregate(
- Sum('vote')).get('vote__sum') or 0
- # serializer = self.serializer_class(self.object, many=True)
- return Response({"rating_count": rating_count})
Advertisement
Add Comment
Please, Sign In to add comment