Friday, February 28, 2020

Re: Api

halo having 2 issues now
(1st) getting an integrity err
(2nd) i have a api code that return's count but still i'm not getting wat i expected
below is my codes and the err msg i'm getting

###APIView
class CartViewSet(viewsets.ModelViewSet):      serializer_class = CartDetailSerializer      queryset = CartList.objects.all()          #@detail_route(methods=['post', 'put'])      def add_item(request, self, pk=None):          cart = self.get_object()          try:              product = Product.objects.get(                  pk = request.data['product_id']              )              quantity = int(request.data['quantity'])          except Exception as e:              print (e)              return Response({'status': 'fail' })            if product.quantity < 0 or product.quantity - quantity < 0:              print('sorry check back leta')              return Response({'status': 'fail'})             existing_cart = CartList.objects.filter(product=product,                     cart=cart).first()          if existing_cart:              existing_cart.quantity +=quantity              existing_cart.save()          else:              new_cart = CartList(cart=cart, product=product,                           quantity=quantity)              new_cart.save()              product_list =                Product.Objects.filter(manufacturer=manufacturer).count()          serializer = CartSerializer(cart)          return Response(serializer.data)

Serializer

class CartDetailSerializer(serializers.ModelSerializer):      customer = UserSerializer(read_only =True)      items = serializers.StringRelatedField(many=True)        class Meta:          model = CartList          fields = ('id', 'customer', 'items', 'created', 'updated')      class CartListSerializer(serializers.ModelSerializer):      class Meta:          model = CartList          fields = ('product', 'quantity')

On Fri, Feb 28, 2020 at 1:28 PM Naveen Arora <naveenarorakrnl@gmail.com> wrote:
Create an API which returns count, then use javascript to update the front end part.


On Friday, 28 February 2020 12:50:39 UTC+5:30, Tosin Ayoola wrote:
Good morning guyz,  
I need help on this one,  it on writing api that will Shows the product count for each manufacturer as users add products real time. 
I have no idea how to solve this problem,  i will any suggestion 
Thanks 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cf4ed839-2cd7-4517-b3d1-b51b3c7a89ee%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHLKn728txLEw9E4G00bZnBZzro8fccPeb6NvZAGU4SyW%2BuPrg%40mail.gmail.com.

1 comment:

  1. This is how my associate Wesley Virgin's report launches in this SHOCKING and controversial VIDEO.

    Wesley was in the army-and soon after leaving-he unveiled hidden, "mind control" secrets that the CIA and others used to get everything they want.

    These are the same SECRETS lots of celebrities (notably those who "come out of nothing") and top business people used to become rich and successful.

    You've heard that you only use 10% of your brain.

    That's really because the majority of your brain's power is UNCONSCIOUS.

    Maybe this expression has even occurred IN YOUR own head... as it did in my good friend Wesley Virgin's head around seven years back, while driving a non-registered, beat-up garbage bucket of a car without a license and $3.20 in his pocket.

    "I'm very fed up with going through life check to check! When will I finally make it?"

    You've taken part in those types of questions, isn't it so?

    Your success story is waiting to be written. Go and take a leap of faith in YOURSELF.

    CLICK HERE TO LEARN WESLEY'S METHOD

    ReplyDelete