[Django]-How to make DRF serializer compatible with uppercase

0👍

Unfortunately i don’t think there is any easy way to accomplish this. What you can do however is to have a write serializer which will do this for you.

class WriteSerializer(serializers.ModelSerializer):
    userName = serializers.CharField(source='username', write_only=True)
    class Meta:
       model = MyModel
       fields = ['userName']

class ReadSerializer(serializers.ModelSerializer):
    class Meta:
       model = MyModel
       fields = ['username']

I’m not sure but you can also do it in one model by manually specifying all the fields and telling which field is write_only and which is ready_only, but that also is a lot of work I assume.

👤Mehran

Leave a comment