Reputation: 6849
In my serializers.py, I created a UserListSerializer:
class UserListSerializer(ModelSerializer):
class Meta:
model = User
fields = '__all__'
exclude = [
'password',
]
I want to realize the exclude fields function, but failed.
AssertionError at /api/users/list/
Cannot set both 'fields' and 'exclude' options on serializer UserListSerializer.
Is it possible to realize this function, because the fields is too much?
Upvotes: 0
Views: 2828
Reputation: 27503
you cannot use both fields and exclude in the Meta Class of your serializer
instead try this
class UserListSerializer(ModelSerializer):
class Meta:
model = User
exclude = [
'password',
]
Upvotes: 3