B
B
blackbb2015-10-22 04:12:37
Django
blackbb, 2015-10-22 04:12:37

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'Картины'

There was a problem with the basket, I don’t really understand how to implement it. I want to make it simple, i.e. under the picture there is a buy button, when you click on it, the picture goes to the basket, when you go to the cart, the picture hangs in it (three fields: name, author, price) and the checkout button, by clicking on which we go to the page for filling in the fields (address, name, etc. .d.) and a submit button. After clicking it, a letter arrives in the mail with the ordered product and the fields filled in. Like this site oilyoil.com/ru/pictures. Can eat examples of implementation of a simple basket?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KIN1991, 2015-10-22
@blackbb

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 ...

Well, the design view
def checkout(request):
    cart = Images.objects.filter(pk__in=request.session['cart'])
    ....

Something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question