src/customers/api_v1/serializers.py
def create(self, validated_data):
        """
        Overriding the default create method of the Model serializer.
        :param validated_data: data containing all the details of customer
        :return: returns a successfully created customer record
        """
        validated_user = validated_data.pop('user')
        user_data = {
            'username': validated_user.get('email'),
            'first_name': validated_user.get('first_name'),
            'last_name': validated_user.get('last_name'),
            'email': validated_user.get('email')
        }
        try:
            user = UserSerializer.create(UserSerializer(), validated_data=user_data)
        except IntegrityError:
            raise ValidationError({'email': [ErrorDetail(string='A customer with that email already exists', code='invalid')],})
            
        
        customer = Customer.objects.create(user=user,
                            dob=validated_data.pop('dob'))
        return customer

        Overriding the default create method of the Model serializer.
        :param validated_data: data containing all the details of customer
        :return: returns a successfully created customer record
        
Overriding the default create method of the Model serializer.
Overriding the default create method of the Model serializer .
def create(self, validated_data):
        validated_user = validated_data.pop('user')
        user_data = {
            'username': validated_user.get('email'),
            'first_name': validated_user.get('first_name'),
            'last_name': validated_user.get('last_name'),
            'email': validated_user.get('email')
        }
        try:
            user = UserSerializer.create(UserSerializer(), validated_data=user_data)
        except IntegrityError:
            raise ValidationError({'email': [ErrorDetail(string='A customer with that email already exists', code='invalid')],})
        customer = Customer.objects.create(user=user,
                            dob=validated_data.pop('dob'))
        return customer
def create ( self , validated_data ) : validated_user = validated_data . pop ( 'user' ) user_data = { 'username' : validated_user . get ( 'email' ) , 'first_name' : validated_user . get ( 'first_name' ) , 'last_name' : validated_user . get ( 'last_name' ) , 'email' : validated_user . get ( 'email' ) } try : user = UserSerializer . create ( UserSerializer ( ) , validated_data = user_data ) except IntegrityError : raise ValidationError ( { 'email' : [ ErrorDetail ( string = 'A customer with that email already exists' , code = 'invalid' ) ] , } ) customer = Customer . objects . create ( user = user , dob = validated_data . pop ( 'dob' ) ) return customer
Overriding the default create method of the Model serializer.
Overriding the default create method of the Model serializer .
"""
        Overriding the default create method of the Model serializer.
        :param validated_data: data containing all the details of customer
        :return: returns a successfully created customer record
        """
returns a successfully created customer record
returns a successfully created customer record
self
validated_data
data containing all the details of customer
data containing all the details of customer