modified to support custom user model in django 1.5