title: CART functionallity in DRF
body: <p>I am new to Django and currently setting up an ecommerce backend.
  I have created models, serializers, views and urls.</p>
  <p>Now, I need to set up a cart functionality, like create/update/delete/calculate_total and etc.</p>
  <p>The thing is I am totally lost. Don't know where to start and what to do next.
  If you have a little time for quick guidance I'd be sincerely grateful.</p>
  <pre><code>class Cart(models.Model):
      owner = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True)
      number_of_items = models.PositiveIntegerField(default=0)
      total = models.DecimalField(default=0.00, max_digits=5, decimal_places=2)
  
  
      def __str__(self):
          return &quot;User: {}, items in cart: {}&quot;.format(self.owner, self.number_of_items)
  
  
  
  class CartItem(models.Model):
      cart = models.ForeignKey(Cart, on_delete=models.CASCADE, default=None)
      item = models.ForeignKey(Product, on_delete=models.CASCADE)
      quantity = models.PositiveIntegerField()
  
      def __str__(self):
          return str(self.id)
  
  
  
  class CartSerializer(serializers.ModelSerializer):
      owner = serializers.StringRelatedField()
      class Meta:
          model = Cart
          fields = '__all__'
  
  
  class CartItemSerializer(serializers.ModelSerializer):
      class Meta:
          model = CartItem
          fields = &quot;__all__&quot;
  
  
  
  class CartView(viewsets.ModelViewSet):
      serializer_class = CartSerializer
      queryset = Cart.objects.filter()
  
      def perform_create(self, serializer):
          serializer.save(owner=self.request.user)
  
  class CartItemView(viewsets.ModelViewSet):
      serializer_class = CartItemSerializer
      queryset = CartItem.objects.all()
  
  
  
  router = DefaultRouter()
  
  router.register(r'view', CartView)
  router.register(r'item', CartItemView)
  
  urlpatterns = [
      path('', include(router.urls)),
  ]
  </code></pre>