def create_answer(request, question_id): ans = Answer() ans.question = Question.objects.get(pk=question_id) ans.author = request.user ans.content = request.POST['content'] ans.is_better = False ans.save() return HttpResponseRedirect(reverse('question-details', args=(question_id,)))
def deal_with_answer(request, question): form = AnswerForm(request.POST) print('arrive deal_with_answer') if form.is_valid(): answer = form.cleaned_data['answer'] c = Answer(answerer=request.user.profile, belong_to_question=question) c.content = answer c.save() return AnswerForm else: return form
def answer_from_json(json): answer = Answer() answer.content = json['content'] answer.question_id = json['questionId'] return answer