from rest_framework import serializers
from rest_auth.registration.serializers import RegisterSerializer
from . import models

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CustomUser
        fields = ('username', 'first_name', 'last_name' )
        lookup_field = 'username'
        extra_kwargs = {
            'username': {'validators': []},
        }

class RegisterSerializer(RegisterSerializer):
    """
    User Serializer with First Name and Last Name added
    """
    first_name = serializers.CharField(required=True, write_only=True)
    last_name = serializers.CharField(required=True, write_only=True)

    def get_cleaned_data(self):
        data_dict = super().get_cleaned_data()
        data_dict['first_name'] = self.validated_data.get('first_name', '')
        data_dict['last_name'] = self.validated_data.get('last_name', '')
        return data_dict

from rest_framework import serializers
from rest_auth.registration.serializers import RegisterSerializer
from . import models

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CustomUser
        fields = ('username', 'first_name', 'last_name' )
        lookup_field = 'username'
        extra_kwargs = {
            'username': {'validators': []},
        }

class RegisterSerializer(RegisterSerializer):
    """
    User Serializer with First Name and Last Name added
    """
    first_name = serializers.CharField(required=True, write_only=True)
    last_name = serializers.CharField(required=True, write_only=True)

    def get_cleaned_data(self):
        data_dict = super().get_cleaned_data()
        data_dict['first_name'] = self.validated_data.get('first_name', '')
        data_dict['last_name'] = self.validated_data.get('last_name', '')
        return data_dict

User Serializer with First Name and Last Name added