django add to cart

try this https://pypi.org/project/django-shopping-cart/

Here is what the above code is Doing:
1. We’re creating a new view called CartView.
2. We’re using the @login_required decorator to make sure that only logged in users can access this view.
3. We’re using the @method_decorator decorator to make sure that only POST requests can access this view.
4. We’re using the @csrf_exempt decorator to make sure that our view is exempt from CSRF protection.
5. We’re getting the cart from the request.session object.
6. We’re getting the product_id from the request.POST object.
7. We’re getting the quantity from the request.POST object.
8. We’re getting the product from the Product model.
9. We’re adding the product to the cart.
10. We’re saving the cart to the request.session object.
11. We’re redirecting the user to the cart page.