parameters: (request)
docstring: List  products, or create a new product.
docstring_summary: List  products, or create a new product.
docstring_tokens: List products or create a new product .
function: def product_list(request):
      """
      List  products, or create a new product.
      """
      if request.method == 'GET':
          data = []
          nextPage = 1
          previousPage = 1
          products = Product.objects.all()
          page = request.GET.get('page', 1)
          paginator = Paginator(products, 10)
          try:
              data = paginator.page(page)
          except PageNotAnInteger:
              data = paginator.page(1)
          except EmptyPage:
              data = paginator.page(paginator.num_pages)
  
          serializer = ProductSerializer(data,context={'request': request} ,many=True)
          if data.has_next():
              nextPage = data.next_page_number()
          if data.has_previous():
              previousPage = data.previous_page_number()
          
          return Response({'data': serializer.data , 'count': paginator.count, 'numpages' : paginator.num_pages, 'nextlink': '/api/products/?page=' + str(nextPage), 'prevlink': '/api/products/?page=' + str(previousPage)})
  
      elif request.method == 'POST':
          serializer = ProductSerializer(data=request.data)
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data, status=status.HTTP_201_CREATED)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
function_tokens: def product_list ( request ) : if request . method == 'GET' : data = [ ] nextPage = 1 previousPage = 1 products = Product . objects . all ( ) page = request . GET . get ( 'page' , 1 ) paginator = Paginator ( products , 10 ) try : data = paginator . page ( page ) except PageNotAnInteger : data = paginator . page ( 1 ) except EmptyPage : data = paginator . page ( paginator . num_pages ) serializer = ProductSerializer ( data , context = { 'request' : request } , many = True ) if data . has_next ( ) : nextPage = data . next_page_number ( ) if data . has_previous ( ) : previousPage = data . previous_page_number ( ) return Response ( { 'data' : serializer . data , 'count' : paginator . count , 'numpages' : paginator . num_pages , 'nextlink' : '/api/products/?page=' + str ( nextPage ) , 'prevlink' : '/api/products/?page=' + str ( previousPage ) } ) elif request . method == 'POST' : serializer = ProductSerializer ( data = request . data ) if serializer . is_valid ( ) : serializer . save ( ) return Response ( serializer . data , status = status . HTTP_201_CREATED ) return Response ( serializer . errors , status = status . HTTP_400_BAD_REQUEST )