Django 1.6 compatible.

Some changes to make compatible with django 1.6