Wednesday, March 25, 2009

django-cart released!

Until now, if you had to develop an online store in django, you had two options, use satchmo, or write your own code. Satchmo is a huge application that tries to provide everything for all the cases, so for a simple shop you've to deal with hundreds of features that you're not going to use, and in some case it won't be enough flexible.

So what I've not any complain for satchmo, the fact is that is not the ideal solution for some cases as some small shops with few options.

With that said, this post is to announce the release of a new project that could help some people to do simple web shops in a very simple way. This project is django-cart.

While django-cart already existed, it was an unfinished (and unmaintained) project by Eric Woundenberg, to whom I'm very thankful for letting reuse it's project, and avoid confusion.

So, what's django-cart. Django Cart is basically a django application that provides a Cart class, with add/remove/update and get methods to be used for storing products. The products model isn't included in the application, so you can define your products with the fields you need. Then you just need something like...

product_to_add = MyProductModel.objects.get(id=whatever)
cart = Cart(request)
cart.add(product_to_add, product_to_add.price)

and your product will be saved on the database, on a session based cart. Getting the content of the cart is as easy as itering the cart instance.

And basically that's it. More information is available on the project page. Just note that the current version of the application is unstable, and hasn't been tested enough, so feel free to use it, but consider that you'll have to test it by yourself and report/fix some bugs.

I hope all you like it!


  1. thank you! very useful

  2. python syncdb doesn't work.

    _mysql_exceptions.OperationalError: (1054, "Unknown column 'cart_cart.creation_date' in 'order clause'")

  3. Once I commented out the following line syncdb worked:
    ordering = ('-creation_date',)

    (from Cart)

  4. Can't figure out why you got that error... Line looks to be ok, and it's working for me.

    Does the column exist on database? That error usually happens when your model has a column that doesn't exist in database...

  5. The database doesn't exist until I run syncdb. But syncdb fails because of that line. Interesting. Maybe its a mysql problem, are you using mysql?

  6. I've just tried it on sqlite for now, I'll try on mysql and let you know.

  7. Hola Marc, se que hablas español porque vi tu profile en linked. Soy muy novato en esto de django y he implementado django-cart sin ningun problema, es solo que tengo unas dudas porque como te mencione anteriormente, soy muy muy newbie aqui. Duda: como haria para cambiar el ItemAlreadyExists e interpretarlo como incrementarle al quantity actual de ese Item?, te lo pregunto porque lo que puedo entender de es que tiene los metodos CRUD pero no estan totalmente implementados. gracias hermano (desde colombia)

  8. Hola Luis,

    si entiendo bien lo que me preguntas, lo que quieres es que si insertas un producto más de una vez, en lugar de fallar, incremente el contador... yo no cambiaría django-cart, yo haría algo como:

    except ItemAlreadyExists:

    Saludos desde Catalunya amigo colombiano! :)

  9. Just as an FYI for newer Python devs, to catch the ItemAlreadyExists and ItemDoesNotExist exceptions remember to import them into your views before you try to use them.

  10. Hello!

    Is this project still maintained?

    I was looking at Satchmo & LFS, but both seems way too complicated for our needs (small company 'selling' only services), so I'm curious if the project is still alive?


  11. No, really. Actually the code has few things missing, and a known bug.

    But I would use it anyway, and you'll fix all this stuff easily, and it'll work much better than any of this projects, I think.

    And if you do so, it'll be great if you can contribute your changes back to the project.

    Thank you!

  12. How does one view the items of the cart in Django Admin, and also on a template?