4👍
The DRF serializer calls the default create()
method of the model and it won’t call the .set_password()
method. So, You have to call the method explicitly in your create() method of UserSerializer
class UserSerializer(serializers.ModelSerializer):
# other code
def create(self, validated_data):
password = validated_data.pop('password', None)
user_instance = super().create(validated_data)
if password:
user_instance.set_password(password)
user_instance.save()
return user_instance
👤JPG
Source:stackexchange.com