📜  如果存在于另一个表中,rest api django 返回值 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:17.341000             🧑  作者: Mango

代码示例1
class PostSerializer(serializers.ModelSerializer):
    replied = serializers.SerializerMethodField('has_replies')

    def has_replies(post):
        return post.replies.filter(owner=self.context["request"].user).exists()

    class Meta:
        fields = ('id', 'name', 'replied')