mirror of
https://github.com/task-17-lct/backend.git
synced 2024-11-24 07:33:43 +03:00
32 lines
784 B
Python
32 lines
784 B
Python
from django.contrib.auth import get_user_model
|
|
from rest_framework import serializers
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = ["username", "email"]
|
|
|
|
|
|
class UserRegisterSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = ("username", "email", "password")
|
|
extra_kwargs = {
|
|
"password": {"write_only": True},
|
|
"email": {"required": True},
|
|
}
|
|
|
|
def create(self, validated_data):
|
|
user = User.objects.create(
|
|
username=validated_data["username"],
|
|
email=validated_data["email"],
|
|
)
|
|
|
|
user.set_password(validated_data["password"])
|
|
user.save()
|
|
|
|
return user
|