how i exclude password from nested model serializer django rest framework

Solutions on MaxInterview for how i exclude password from nested model serializer django rest framework by the best coders in the world

showing results for - "how i exclude password from nested model serializer django rest framework"
Amy
10 Feb 2019
1#overwrite field you want with new serializer
2class UserSerializer(serializers.ModelSerializer):
3
4    class Meta:
5        model = User
6        exclude = (
7            'password', 'last_login', 'is_superuser', 'email',
8            'gender', 'verify_code', 'created_on', 'is_active',
9            'is_staff', 'groups', 'user_permissions', 'courses'
10        )
11
12
13class ResponseCommentSerializer(serializers.ModelSerializer):
14
15    user_response = UserSerializer()
16
17    class Meta:
18        model = ResponseComment
19        fields = '__all__'
20        depth = 1
21
22
23class CommentSerializer(serializers.ModelSerializer):
24
25    user = UserSerializer()
26    response = ResponseCommentSerializer(many=True, read_only=True)
27
28    class Meta:
29        model = Comment
30        fields = '__all__'
31        depth = 2
32