Exemple #1
0
class ProductViewSet(viewsets.ModelViewSet):
    queryset = Product.objects.all()
    serializer = ProductSerializer(queryset, many=True)
    serializer_class = ProductSerializer
    pagination_class = PageNumberSetPagination

    filter_backends = [filters.SearchFilter]
    search_fields = ['name']
def Product_Detail(request, productID, format=None):

    if request.method == 'GET':
        try:
            item = product.objects.filter(id=productID)
        except product.DoesNotExist:
            raise Response(status=404)
        serializer = ProductSerializer(item, many=True)
        return Response(serializer.data)
def categoryShoe(request, catID, format=None):

    if request.method == 'GET':
        try:
            items = product.objects.filter(category=catID)
        except product.DoesNotExist:
            raise Response(status=404)

        serializer = ProductSerializer(items, many=True)

        return Response(serializer.data)
Exemple #4
0
    def after(self, request, *args, **kwargs):
        # todo:add header
        timestamp = int(request.query_params.get('timestamp'))
        date = datetime.fromtimestamp(timestamp / 1e3)
        pds = Product.objects.filter(
            Q(created_at__gte=date) | Q(updated_at__gte=date)).all()
        product_serialized = ProductSerializer(pds,
                                               many=True,
                                               context={'request': request})

        return Response(product_serialized.data)
def genderShoe(request, genID, format=None):

    if request.method == 'GET':
        try:
            items = product.objects.filter(gender=genID)
        except product.DoesNotExist:
            raise Response(status=404)

        serializer = ProductSerializer(items,
                                       context={'request': request},
                                       many=True)
        return Response(serializer.data)
def detailPage(request, productID, format=None):

    if request.method == 'GET':
        try:
            items = product.objects.filter(id=productID)
            Size = size.objects.all()
        except product.DoesNotExist:
            raise Response(status=404)
        data = {}
        serializer = ProductSerializer(items, many=True)
        data['product'] = serializer.data
        serializer = SizeSerializer(Size, many=True)
        data['size'] = serializer.data
        data['success'] = True
        return Response(data)