The following example doesn't work as expected, and returns a validation error. Why is that?
from rest_framework import serializers
class TestSerializer(serializers.Serializer):
from_field = serializers.CharField(source='from')
subject = serializers.CharField()
data = {'from': '[email protected]', 'subject': 'hi'}
s = TestSerializer(data=data)
print(s.is_valid()) # prints False
print(s.errors) # prints {'from_field': [ErrorDetail(string='This field is required.', code='required')]}
What I am looking to do is map an external POST data which has the protected word from, and validate the input with the serializer. If the above is not expected to work, what alternatives exist?
to_internal_valuemethod for input orto_representationfor output