Category Archives: Django

Make sure you are closing the DB connections after accessing Django ORM in your threads

I was writing a service which import various feeds and then post to another RESTful API, simple enough as below:

Then the feed model:

Then run this feed in trivial code:

And you will quickly notice the threads complaining

What it’s happening is Django will create a new connection per thread… Read More »

Laravel for Django developers, part 2

Global functions I am seeing a lot of framework specific global functions but don’t know where they come from, such as “view()”, “redirect()” etc etc. ORM Again, as mentioned in part 1, since we are creating migration files first, then we won’t be able to define FK relationships directly point to another model. According to… Read More »

Laravel for Django developers, part 1

Project Structure After setting up the quickstart project, I feel the project structure is quite different to Django. In Django a lot of code are organised in “app” domain, but it seems to me that multi-app is not something out-of-the-box in Laravel: https://laracasts.com/discuss/channels/general-discussion/laravel-5-multi-app-or-modular-applications Instead, it seems the apps in Django is more similar to the… Read More »

Laravel for Django Developers, prelude.

Reality is a b**ch, Python/Django jobs are scarce in New Zealand, despite how awesome the framework it is, managers and architects still choose PHP frameworks such as Silverstripe over Django, besides, Silverstripe is a CMS, not a framework. After 5 years of dedication to Django framework, I struggle to find Django jobs in New Zealand.… Read More »

django-rest-framework: api versioning

Django Rest Framework is a very solid api framework, but it doesn’t provide out-of-box versioning mechanism, here is my attempt to implement version specific APIs. The goal is to achieve something like http://localhost:8000/api/(resource)/ http://localhost:8000/api/v1/(resource)/ plus allowing clients to specify the version in request header (X-Version), here is how we did it. Structure in side the… Read More »

Django CMS Haystack 2.0 Search Index

Currently django-cms-search doesn’t support haystack 2.0 yet, so here is my modified version to work on haystack 2.0 based on

Django admin UnicodeEncodeError

Don’t we all get confused by unicode encoding sometimes? Especially you wouldn’t expect this kind of error to happen in django admin. The problem is actually not in the admin section, the culprit is __unicode__ method in your model. when you have a unicode function like this:

It is actually returning a ASCII string(which… Read More »