from django.http import HttpResponse
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Product
from .serializers import ProductSerializer


class ProductList(APIView):
    def get(self, request, format=None):
        products = Product.objects.all()
        serializer = ProductSerializer(products, many=True)
        return Response(serializer.data)

from django.http import HttpResponse
from rest_framework import generics
from rest_framework.response import Response
from .models import Product
from .serializers import ProductSerializer


class ProductList(generics.ListAPIView):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer

Implement GET Product using ListAPIView
Implement GET Product using ListAPIView

  from django.http import HttpResponse
- from rest_framework.views import APIView
+ from rest_framework import generics
  from rest_framework.response import Response
  from .models import Product
  from .serializers import ProductSerializer
  
  
- class ProductList(APIView):
+ class ProductList(generics.ListAPIView):
-     def get(self, request, format=None):
-         products = Product.objects.all()
+     queryset = Product.objects.all()
+     serializer_class = ProductSerializer
-         serializer = ProductSerializer(products, many=True)
-         return Response(serializer.data)
  
Implement GET Product using ListAPIView
## Code Before:
from django.http import HttpResponse
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Product
from .serializers import ProductSerializer


class ProductList(APIView):
    def get(self, request, format=None):
        products = Product.objects.all()
        serializer = ProductSerializer(products, many=True)
        return Response(serializer.data)

## Instruction:
Implement GET Product using ListAPIView
## Code After:
from django.http import HttpResponse
from rest_framework import generics
from rest_framework.response import Response
from .models import Product
from .serializers import ProductSerializer


class ProductList(generics.ListAPIView):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer
