Answers for "how i exclude password from nested model.serializer django rest framework"

0

how i exclude password from nested model.serializer django rest framework

#overwrite field you want with new serializer
class UserSerializer(serializers.ModelSerializer):

    class Meta:
        model = User
        exclude = (
            'password', 'last_login', 'is_superuser', 'email',
            'gender', 'verify_code', 'created_on', 'is_active',
            'is_staff', 'groups', 'user_permissions', 'courses'
        )


class ResponseCommentSerializer(serializers.ModelSerializer):

    user_response = UserSerializer()

    class Meta:
        model = ResponseComment
        fields = '__all__'
        depth = 1


class CommentSerializer(serializers.ModelSerializer):

    user = UserSerializer()
    response = ResponseCommentSerializer(many=True, read_only=True)

    class Meta:
        model = Comment
        fields = '__all__'
        depth = 2
Posted by: Guest on September-08-2021

Code answers related to "how i exclude password from nested model.serializer django rest framework"

Python Answers by Framework

Browse Popular Code Answers by Language