Refactoring for newer Django (1.5/1.6)