mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 14:04:07 +01:00
28 lines
876 B
Python
28 lines
876 B
Python
from rest_framework import serializers
|
|
from .models import CustomUser
|
|
|
|
|
|
class CustomUserSerializer(serializers.ModelSerializer):
|
|
"""
|
|
Serializer for CustomUser model.
|
|
"""
|
|
email = serializers.EmailField(required=True)
|
|
username = serializers.CharField(required=True)
|
|
password = serializers.CharField(min_length=8, write_only=True)
|
|
|
|
class Meta:
|
|
model = CustomUser
|
|
fields = ('email', 'password')
|
|
extra_kwargs = {'password': {'write_only': True}}
|
|
|
|
def create(self, validated_data):
|
|
"""
|
|
Create a CustomUser instance with validated data, including password hashing.
|
|
"""
|
|
password = validated_data.pop('password', None)
|
|
instance = self.Meta.model(**validated_data)
|
|
if password is not None:
|
|
instance.set_password(password)
|
|
instance.save()
|
|
return instance
|