django 1.6 fix, also simplifies code for 1.7