Changed the code to work with django 1.5