modified to make django 1.6 compatible