Django - Part 2 -Creating a cart/Getting a Cart(Lesson4 & 5))

Hello all,

I am currently going through the Django series - Part -2. In lesson 4 - Creating a cart when we make id = UUIDField(read_only = True) an empty object was generated and if we click on POST in the cart then it generates a 32-character id.

After that, if I add ‘items’ in CartSerializer and CartItem as per the video if mosh refreshes it shows generated id and an empty array with items. But in my case, if I am refreshing the webpage it shows the page with the “detail GET method not allowed”.

After adding the generated id in datagrip in columns as per the video but the same error is showing. I can’t see my cart items in any way.

That’s because the CartViewSet doesn’t allow for getting the Cart List:

class CartViewSet(CreateModelMixin,
    queryset = Cart.objects.prefetch_related('items__product').all()
    serializer_class = CartSerializer

But if you paste the UUID in the url bar it will pull up that specific cart and its items.