[英]How to add Product to shopping cart?
How to add Product from this model to shopping cart: https://github.com/bmentges/django-cart How to run method add_to_cart ? 如何将产品从此模型添加到购物车: https : //github.com/bmentges/django-cart如何运行方法add_to_cart ? In template I would have button "add to cart". 在模板中,我将具有“添加到购物车”按钮。 Thanks 谢谢
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
What are quantity
and unit_price
from a basic usage of django-cart: https://github.com/bmentges/django-cart ? 什么是quantity
和unit_price
从Django的购物车的基本用法: https://github.com/bmentges/django-cart ?
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)
What are quantity and unit_price from a basic usage of django-cart: django-cart的基本用法是数量和单价:
Quantity is the number of that product in your line item. 数量是订单项中该产品的数量。
If you say 3, it means there are 3 of the "product" in your cart. 如果您说3,则表示购物车中有3个“产品”。 This is typically related to an input type='text'
field with an add to cart button next to it. 这通常与input type='text'
字段相关,旁边是添加到购物车按钮。
unit_price
is the price of a single unit of your product. unit_price
是产品的单个单位的价格。 It is not automatically pulled from the product because it may well differ from what the product price actually is. 它不会自动从产品中拉出,因为它可能与产品实际价格有很大差异。
For example, maybe there's a 20% sale; 例如,也许有20%的销售; this system allows you to have prices in the cart that differ from the product price. 此系统使您可以在购物车中获得与产品价格不同的价格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.