HiPhone_BE/user/serializers.py

35 lines
777 B
Python

from rest_framework.serializers import ModelSerializer
from .models import User
class UserSerializer(ModelSerializer):
class Meta:
model = User
fields = (
"id",
"username",
"nickname",
)
class UserCreateSerializer(ModelSerializer):
class Meta:
model = User
fields = (
"username",
"password",
"nickname",
)
extra_kwargs = {
"password": {"write_only": True},
}
def create(self, validated_data):
user = User.objects.create_user(
username=validated_data["username"],
password=validated_data["password"],
nickname=validated_data["nickname"],
)
return user