如何将此模型中的产品添加到购物车:https ://github.com/bmentges/django-cart 如何运行方法add_to_cart?在模板中,我会有“添加到购物车”按钮。谢谢
from django.db import models
from sorl.thumbnail import ImageField
class Product(models.Model):
name = models.CharField(max_length=50)
slug = models.SlugField()
price = models.DecimalField(max_digits=5, decimal_places=2)
desc = models.TextField()
image = ImageField(upload_to='images')
class Meta:
verbose_name = _('Product')
verbose_name_plural = _('Products')
def __unicode__(self):
return self.name
django-cart 的基本用法是什么quantity
以及来自: https ://github.com/bmentges/django-cart ?unit_price
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)