# Path: api/serializers.py
# class ProductSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Product
#         fields = ('id', 'name', 'wholesale_price', 'retail_price')
# 
# class NoteSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Note
#         fields = ('id', 'title', 'user', 'details', 'category', 'is_active', 'created_at')
# 
# class CategorySerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Category
#         fields = ('id', 'name', 'user')
# 
# Path: common/models.py
# class Product(models.Model):
#     """
#     product model for the items etc.
#     """
#     name = models.CharField(max_length=64)
#     description = models.CharField(max_length=1024, unique=True)
#     wholesale_price = models.PositiveIntegerField(default=0)
#     retail_price = models.PositiveIntegerField(default=0)
#     img = models.ImageField(upload_to = 'prod_imgs/', default = 'prod_imgs/default.png')
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     def __unicode__(self):
#         """
#         function returns unicode representation of a product
#         """
#         return self.name
# 
# Path: notes/models.py
# class Category(models.Model):
#     """
#     category for a note
#     """
#     name = models.CharField(max_length=64)
#     user = models.ForeignKey(User)
# 
#     def __unicode__(self):
#         """
#         function returns unicode representation of a category
#         """
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "categories"
# 
# class Note(models.Model):
#     """
#     model for a note
#     """
#     title = models.CharField(max_length=64)
#     user = models.ForeignKey(User)
#     details = models.TextField()
#     category = models.ForeignKey(Category)
#     is_active = models.BooleanField(default=True)
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     def __unicode__(self):
#         """
#         function returns unicode representation of a note
#         """
#         return self.title


from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser
from api.serializers import ProductSerializer, NoteSerializer, CategorySerializer
from common.models import Product
from notes.models import Category, Note
            )
    resp["error"] = 0
    resp["message"] = "Registration successful"
    return JSONResponse(resp, status=400)

@csrf_exempt
def product_list(request):
    """
    List all code products, or create a new product.
    """
    if request.method == 'GET':
        products = Product.objects.all()	
        serializer = ProductSerializer(products, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = ProductSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)


@csrf_exempt
def product_detail(request, pk):
    """
    functions retrieves, updates or deletes a product.
    """
    try:

# Path: api/serializers.py
# class ProductSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Product
#         fields = ('id', 'name', 'wholesale_price', 'retail_price')
# 
# class NoteSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Note
#         fields = ('id', 'title', 'user', 'details', 'category', 'is_active', 'created_at')
# 
# class CategorySerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Category
#         fields = ('id', 'name', 'user')
# 
# Path: common/models.py
# class Product(models.Model):
#     """
#     product model for the items etc.
#     """
#     name = models.CharField(max_length=64)
#     description = models.CharField(max_length=1024, unique=True)
#     wholesale_price = models.PositiveIntegerField(default=0)
#     retail_price = models.PositiveIntegerField(default=0)
#     img = models.ImageField(upload_to = 'prod_imgs/', default = 'prod_imgs/default.png')
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     def __unicode__(self):
#         """
#         function returns unicode representation of a product
#         """
#         return self.name
# 
# Path: notes/models.py
# class Category(models.Model):
#     """
#     category for a note
#     """
#     name = models.CharField(max_length=64)
#     user = models.ForeignKey(User)
# 
#     def __unicode__(self):
#         """
#         function returns unicode representation of a category
#         """
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "categories"
# 
# class Note(models.Model):
#     """
#     model for a note
#     """
#     title = models.CharField(max_length=64)
#     user = models.ForeignKey(User)
#     details = models.TextField()
#     category = models.ForeignKey(Category)
#     is_active = models.BooleanField(default=True)
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     def __unicode__(self):
#         """
#         function returns unicode representation of a note
#         """
#         return self.title


# Path: api/views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser
from api.serializers import ProductSerializer, NoteSerializer, CategorySerializer
from common.models import Product
from notes.models import Category, Note

            )
    resp["error"] = 0
    resp["message"] = "Registration successful"
    return JSONResponse(resp, status=400)

@csrf_exempt
def product_list(request):
    """
    List all code products, or create a new product.
    """
    if request.method == 'GET':
        products = Product.objects.all()	
        serializer = ProductSerializer(products, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = ProductSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)


@csrf_exempt
def product_detail(request, pk):
    """
    functions retrieves, updates or deletes a product.
    """
    try:

        room = Product.objects.get(pk=pk)