Modified to work with python 2.x and 3.x

Tested on python 3.3, 2.7 and Django versions 1.4 and 1.6.