from django.http import HttpResponse
from django.http import Http404
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from .permissions import IsAdminOrReadOnly
from .models import Product
from .serializers import ProductSerializer


class ProductList(generics.ListCreateAPIView):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer
    permission_classes = (IsAdminOrReadOnly, )


class ProductDetail(APIView):
    def get_object(self, pk):
        try:
            return Product.objects.get(pk=pk)
        except Product.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        product = self.get_object(pk)
        serializer = ProductSerializer(product)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        product = self.get_object(pk)
        serializer = ProductSerializer(product, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        product = self.get_object(pk)
        product.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

@@ -2,226 +2,37 @@
 rom 
-django.http import HttpResponse%0Afrom django.http import Http404%0Afrom rest_framework import generics%0Afrom rest_framework.response import Response%0Afrom rest_framework.views import APIView%0Afrom rest_framework import statu
+rest_framework import generic
 s%0Afr
@@ -343,849 +343,169 @@
 ail(
-APIView):%0A    def get_object(self, pk):%0A        try:%0A            return Product.objects.get(pk=pk)%0A        except Product.DoesNotExist:%0A            raise Http404%0A%0A    def get(self, request, pk, format=None):%0A        product = self.get_object(pk)%0A        serializer = ProductSerializer(product)%0A        return Response(serializer.data)%0A%0A    def put(self, request, pk, format=None):%0A        product = self.get_object(pk)%0A        serializer = ProductSerializer(product, data=request.data)%0A        if serializer.is_valid():%0A            serializer.save()%0A            return Response(serializer.data)%0A        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)%0A%0A    def delete(self, request, pk, format=None):%0A        product = self.get_object(pk)%0A        product.delete()%0A        return Response(status=status.HTTP_204_NO_CONTENT
+generics.RetrieveUpdateDestroyAPIView):%0A    queryset = Product.objects.all()%0A    serializer_class = ProductSerializer%0A    permission_classes = (IsAdminOrReadOnly, 
 )%0A

Implement ProductDetail with a generic RetrieveUpdateDestroyAPIView class