Answer the question
In order to leave comments, you need to log in
Simple shopping cart in Django?
Hello. I'm making a site for selling paintings and it's on django. The model is like this:
class Authors(models.Model):
fio = models.CharField(max_length=200, verbose_name=u'Ф.И.О')
slug = models.SlugField(unique = True)
background = models.ImageField(upload_to='background')
biography = HTMLField(verbose_name=u'Биография')
class Meta:
verbose_name = u'Художник'
verbose_name_plural = u'Художники'
def __unicode__(self):
return u'%s' % self.fio
class Images(models.Model):
image = models.ImageField(upload_to='pictures', verbose_name=u'Изображение')
slug = models.SlugField(unique = True)
authors = models.ForeignKey(Authors, verbose_name=u'Автор')
title = models.CharField(max_length=200, verbose_name=u'Название')
size = models.CharField(max_length=50, verbose_name=u'Размер')
year = models.CharField(max_length=20, verbose_name=u'Год')
price = models.CharField(max_length=50, verbose_name=u'Цена')
sales = models.BooleanField(max_length=100, verbose_name=u'Продано')
genre = models.CharField(max_length=200, verbose_name=u'Жанр')
color = models.CharField(max_length=100, verbose_name=u'Цвет')
class Meta:
verbose_name = u'Картины'
verbose_name_plural = u'Картины'
Answer the question
In order to leave comments, you need to log in
Everything is simple when you click on the buy button, you should send the id-ik of the picture to the basket session, when you proceed to checkout, just make a request to the database with the output of the information you need by the id-s that you have in the session.
Cart View
def cart(request,id):
if 'cart' not in request.session:
request.session['cart'] = list()
request.session['cart'].append(int(id))
....
return ...
def checkout(request):
cart = Images.objects.filter(pk__in=request.session['cart'])
....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question