1class PostSerializer(serializers.ModelSerializer):
2 replied = serializers.SerializerMethodField('has_replies')
3
4 def has_replies(post):
5 return post.replies.filter(owner=self.context["request"].user).exists()
6
7 class Meta:
8 fields = ('id', 'name', 'replied')
1class PostList(generics.ListAPIView):
2 ...
3 def get_queryset(self):
4 Post.objects.all().extra(select={
5 'current_user_replies_count': 'SELECT COUNT(*) FROM <reply table> WHERE' +
6 'post_id=posts_post.id AND owner_id = %s'
7 },select_params=(request.user.id,))