def category_products(request, pk): if request.method == 'GET': category = Category.objects.get(id=pk) products = category.products_set.all() serializer = ProductsSerializer(products, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = ProductsSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response({'error': serializer.errors}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def post(self, request): serializers = ProductsSerializer(data=request.data) if serializers.is_valid(): serializers.save() return Response(serializers.data, status=status.HTTP_201_CREATED) return Response({'errors': serializers.errors}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def put(self, request, id): measure = get_object(id=id) serializer = ProductsSerializer(measure, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, format=None): products = Products.objects.filter( id__in=PropertiesProducts.objects.filter( properties_value).distinct())[:10] #products = Products.objects.all()[:50] serializer = ProductsSerializer(products, many=True) return Response(serializer.data)
def author_products(request, pk): try: author = Authors.objects.get(id=pk) except author.DoesNotExist as e: return Response({'errors': str(e)}) products = author.products_set.all() serializer = ProductsSerializer(products, many=True) return Response(serializer.data)
def get_products(request): """ Result: A JSON consisting of - a JSON of all products in our catalog - a list of categories """ products = Products.objects.all() products_serialized = ProductsSerializer(products, many=True).data category_results = sort_by_field_string(products, lambda x: x.categories) brand_results = sort_by_field_string(products, lambda x: x.brands) return JsonResponse({ "products": products_serialized, "categories": category_results, "brands": brand_results })
def get(self, request, idprotuct, format=None): products = Products.objects.filter(pk=idprotuct) serializer = ProductsSerializer(products, many=True) return Response(serializer.data)
def put(self, request, pk): product = self.get_products(pk) serializer = ProductsSerializer(instance=product, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data)
def get(self, request, pk): product = self.get_products(pk) serializer = ProductsSerializer(product) return Response(serializer.data)
def get(self, request): products = Products.objects.all() serializers = ProductsSerializer(products, many=True) return Response(serializers.data)
def top_products(request): top_list = Products.top_list.all() serializer = ProductsSerializer(top_list, many=True) return Response(serializer.data)
def get(self, request, format=None): queryset = Products.objects.all() serializer = ProductsSerializer(queryset, many=True) return Response(serializer.data)
def post(self, request): serializer = ProductsSerializer(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)
def get(self, request): products = Product.objects.all() print(products) serializedData = ProductsSerializer(products, many=True) return Response(serializedData.data)