Сериализатор:
class GenderSerializer(serializers.Serializer):
name = serializers.SerializerMethodField()
def get_name(self, obj):
print("------------------")
print(obj)
print("------------------")
return "aaa"
# return _(obj.name)
Во вьюхе:
serializer_gender = GenderSerializer(data=[{'id': 1, 'name': 'GENDER_MAN'}, {'id': 2, 'name': 'GENDER_WOMAN'}], many=True)
serializer_gender.is_valid(raise_exception=True)
out:
------------------
{}
------------------
------------------
{}
------------------