没有任何数据可供显示
| 开源项目社区 | 当前位置 : |
|
| www.trustie.net/open_source_projects | 主页 > 开源项目社区 > django-cart |
|
django-cart
|
| 1 | 0 | 8 |
| 贡献者 | 讨论 | 代码提交 |
NOTE: django-cart is a different project starting on March 25th, 2009. Thanks a lot to Eric Woudenberg for letting us reuse this project
django-cart is a very simple application that just let you add and remove items from a session based cart. django-cart doesn't provide any product information, and you've to define your own product models, and then use their instances on the cart.
A basic usage of django-cart could be:
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 %}
Product
Quantity
Total Price
{% for item in cart %}
{{ item.product.name }}
{{ item.quantity }}
{{ item.total_price }}
{% endfor %}
{% endblock %}
标签:
