django_rest_framework を使用してユーザー登録と API を処理するにはどうすればよいですか? 具体的には、UserSerializer でパスワード フィールドを設定するにはどうすればよいですか
class NewUserSerializer(serializer.Serializers):
first_name = serializers.CharField(required=True, max_length=30)
last_name = serializers.CharField(required=True, max_length=30)
username = serlializers.CharField(required=True, max_length=30)
email = serializers.EmailField(required=True)
password = ???
def restore_object(self, attrs, instance=None):
if instance:
instance.username = attrs.get('username', instance.username)
instance.first_name = attrs.get('first_name', instance.first_name)
instance.last_name = attrs.get('last_name', instance.last_name)
instance.email = attrs.get('email', instance.email)
# Would the instance.password field be necessary?
instance.password = attrs.get('password', instance.password)
else:
return User(**attrs)