from rest_framework import serializers

from bliese_api import models


class HelloSerializer(serializers.Serializer):
	"""Serializes name field for testing ourAPIView"""
	name = serializers.CharField(max_length=10)


class UserProfileSerializer(serializers.ModelSerializer):
	"""Serializes a user profile object"""

	class Meta:
		model = models.UserProfile
		fields = ('id', 'email', 'name', 'password')
		extra_kwargs = {
			'password': {
				'write_only': True,
				'style': {
					'input_type': 'password'
				}
			}
		}

	def create(self, validated_data):
		"""Create and return a new user"""
		user = models.UserProfile.objects.create_user(
			email=validated_data['email'],
			name=validated_data['name'],
			password=<PASSWORD>['password']
		)

		return user


class ProductSerializer(serializers.ModelSerializer):
	class Meta:
		model = models.Product
		fields = ('id', 'cat_id', 'item_name', 'item_description', 'price', 'quantity')

from rest_framework import serializers

from bliese_api import models


class HelloSerializer(serializers.Serializer):
	"""Serializes name field for testing ourAPIView"""
	name = serializers.CharField(max_length=10)


class UserProfileSerializer(serializers.ModelSerializer):
	"""Serializes a user profile object"""

	class Meta:
		model = models.UserProfile
		fields = ('id', 'email', 'name', 'password')
		extra_kwargs = {
			'password': {
				'write_only': True,
				'style': {
					'input_type': 'password'
				}
			}
		}

	def create(self, validated_data):
		"""Create and return a new user"""
		user = models.UserProfile.objects.create_user(
			email=validated_data['email'],
			name=validated_data['name'],
			password=<PASSWORD>['password']
		)

		return user


class ProductSerializer(serializers.ModelSerializer):
	class Meta:
		model = models.Product
		fields = ('id', 'cat_id', 'item_name', 'item_description', 'price', 'quantity')

Serializes name field for testing ourAPIView Serializes a user profile object Create and return a new user