Update for django1.5 and master

I've updated code for the changes in django. Tests pass for me on 1.4.x, 1.5.x and master.