Wednesday, September 26, 2012

Django-cart. How to run method add_to_cart?

https://github.com/bmentges/django-cart

I'm a total newbie to Django. How to run method add_to_cart? In template I would have button "add to cart".

Thanks.

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)
My model look something like this:
class Product(models.Model):      name = models.CharField(max_length=50)      slug = models.SlugField()      unit_price = models.DecimalField(max_digits=5, decimal_places=2)      category = models.ManyToManyField(Category)        class Meta:          verbose_name = "Product"          verbose_name_plural = "Products"        def __unicode__(self):          return self.name

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/VnV4Fsbp510J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment