[Answer]-How can I get results from multiple models with Django REST Framework

1👍

You can add custom field to response .

Here we can’t use like . as its reserved keyword in python . See this code . implement same for dislike .

class LikeSerializer(serializers.ModelSerializer):
    user = UserSerializer(required=False)
    likes = serializers.SerializerMethodField('no_likes_get')

    def no_likes_get(self, like_obj):
        return Like.objects.filter(movie_id = like_obj.movie_id).count()

    class Meta:
        model = Like
        fields = ('id', 'user', 'movie_id', 'likes')

Leave a comment