def update(self, instance, validated_data):
    'Update a user, setting the password correctly and return it'
    password = validated_data.pop('password', None)
    user = super().update(instance, validated_data)
    if password:
        user.set_password(password)
        user.save()
    return user
Update a user, setting the password correctly and return it
def update(self, instance, validated_data):
    
    password = validated_data.pop('password', None)
    user = super().update(instance, validated_data)
    if password:
        user.set_password(password)
        user.save()
    return user