[Django]-Django Rest Framework: Overwriting validation error keys

3👍

You can change the name field in the ModelSerializer to username.

example:

class CustomSerializer(serializers.ModelSerializer):
    username = serializers.CharField(source='name')

    class Meta:
        model = ...
        fields = ('username', ...)

Now in validation errors it will have the key username instead.

Leave a comment