modifed for compatibility with django 1.4.2