Updated code for Django 1.6