Modified to support Django 1.5+