I have a custom user for authentication and want to create a serializer class for it my custom user\'s model is like this :
class User (Abs
to hash password, call:
make_password(origin_password)
example serializers.py:
from rest_framework import serializers
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
class UserSerializer(serializers.HyperlinkedModelSerializer):
password = serializers.CharField(
write_only=True,
required=True,
help_text='Leave empty if no change needed',
style={'input_type': 'password', 'placeholder': 'Password'}
)
class Meta:
model = User
fields = ('url', 'username', 'email', 'password')
def create(self, validated_data):
validated_data['password'] = make_password(validated_data.get('password'))
return super(UserSerializer, self).create(validated_data)