def refresh_chapter(chapter): chapter.refresh = True chapter.put() query = Question.all().filter('chapter =', chapter) for q in query.run(): q.refresh = True q.put query = Chapter.all().ancestor(chapter.key()) for c in query.run(): if c != chapter: refresh_chapter(c)