Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

rest api django return value if exists in another table

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')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #rest #api #django #return #exists #table
ADD COMMENT
Topic
Name
8+6 =