django-cart 1.0.1

Django simple shopping cart
django-cart is a very simple Django app 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.

Installation

To install this just type:

python setup.py install

or

pip install django-cart

After installation is complete:

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

Usage

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

# views.py
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)
 cart.remove(product)


def get_cart(request):
 return render_to_response('cart.html', dict(cart=Cart(request)))

# templates/cart.html
{% extends 'base.html' %}

{% block body %}
 < table >
 < tr >
 < th >Product< /th >
 < th >Quantity< /th >
 < th >Total Price< /th >
 < /tr >
 {% for item in cart %}
 < tr >
 < td >{{ item.product.name }}< /td >
 < td >{{ item.quantity }}< /td >
 < td >{{ item.total_price }}< /td >
 < /tr >
 {% endfor %}
 < /table >
{% endblock %}

last updated on:
October 10th, 2011, 10:34 GMT
price:
FREE!
developed by:
Bruno Carvalho
license type:
GPL v3 
category:
ROOT \ Internet \ HTTP (WWW)

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT