Saturday, February 29, 2020

Re: Api

Can you share the traceback of error you are facing ?

Cheers,

On Saturday, 29 February 2020 11:17:59 UTC+5:30, Tosin Ayoola wrote:
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 <naveena...@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...@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/c8a99cd5-7e52-459f-9f17-8d9e5272c963%40googlegroups.com.

No comments:

Post a Comment