def add_answer(self, question_id, source, author): question = Question.get_by_id(int(question_id)) if not question or not source: self.set_error_code(500) return #TODO: if answer is added by anonymouse, author should be set to None, # real_author is always set.(eg. question_relationship = get_relationshiop(question)) new_answer = Answer( parent = question.key, summary = source[0:100], question = question.key, author = author.key, real_author = author.key, content = source.replace("\n", "<br />"), source = source) new_answer.put() relation = AccountQuestionRelationService().get_relationship(author.key, question.key) relation.my_answer = new_answer.key relation.put() QuestionService().update_answer_num(question.key) return new_answer