[Answered ]-How to use count() in serializers?

1👍

language is the object you are serializing, hence you return:

class ArticleSerializer(serializers.ModelSerializer):
    # …

    def get_total_likes(self, language):
        return language.articlelikes.count()

Leave a comment