Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Django simple shopping cart solution, with tests :)
Branch: master

Merge pull request #16 from tfyr/master

update() bug fixed. Thanks @tfyr
latest commit b3c77276c2
@bmentges authored


django-cart is a very simple application that just let you add and remove items from a session based cart. django-cart uses the power of the Django content type framework to enable you to have your own Product model and associate with the cart without having to change anything. Please refer to the tests to see how it's done.


  • Django 1.1+
  • django content type framework in your INSTALLED_APPS
  • south for migrations (optional)


To install this just type:

python install


pip install django-cart

After installation is complete:

  1. add 'cart' to your INSTALLED_APPS directive and
  2. If you have South migrations type: ./ migrate cart
  3. or if you don't: ./ syncdb


A basic usage of django-cart could be (example):

from cart import Cart
from myproducts.models import Product

def add_to_cart(request, product_id, quantity):
    product = Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.add(product, product.unit_price, quantity)

def remove_from_cart(request, product_id):
    product = Product.objects.get(id=product_id)
    cart = Cart(request)

def get_cart(request):
    return render_to_response('cart.html', dict(cart=Cart(request)))
# templates/cart.html
{% extends 'base.html' %}

{% block body %}
            <th>Total Price</th>
        {% for item in cart %}
            <td>{{ }}</td>
            <td>{{ item.quantity }}</td>
            <td>{{ item.total_price }}</td>
        {% endfor %}
{% endblock %}

Some Info

This project was abandoned and I got it and added tests and South migrations, and I will be maintaining it from now on.

Known Problems

Right now the main problem is that it adds a database record for each cart it creates. I'm in the process of studying this and will soon implement something to handle it.

A note on the authors of this project

This project is a fork of django-cart on Google Code. It was originally started by Eric Woudenberg and followed up by Marc Garcia The last change ocurred in March 25 2009, without any tests. My goal is to push this project a little further by adding tests to guarantee it's functionality and to fix the main issues. I intend to keep it as simple as it is.

  • Bruno Carvalho
Something went wrong with that request. Please try again.