def changeanswer(request): if 'origin' in request.GET and 'ques' in request.GET: orig = request.GET['origin'] ques = request.GET['ques'] request.session['questionc'] = ques request.session['ans'] = orig #return HttpResponse(chan) multiple_answer = Answer.objects.get(answer = orig) multiple_question = Questionans(question = ques) return render_to_response('changeans.html',{'answer':multiple_answer,'question':multiple_question}) if request.POST: ans = request.POST['answer'] anso = request.session.get('ans') multiple_answer = Answer.objects.get(answer = anso) ques = request.session.get('questionc') questionall = Question.objects.get(question = ques)# questionall.answers.remove(multiple_answer)#yichu yuanlai de multiple_question = Questionans(question = ques) if (multiple_question): multiple_question.answers.remove(multiple_answer) #multi_answer = Answer.objects.get(answer = anso) #multi_answer.delete()shanchu zhiqian de jiudaan wei multiple_answer.answer = ans multiple_answer.save() multiple_question = Questionans(question = ques)#添加到我的回答中 multiple_question.save() multiple_question.answers.add(multiple_answer) questionall.answers.add(multiple_answer) usern = request.session.get('username')#baoun user1 = User.objects.get(username = usern) user1.myanswers.add(multiple_question) del request.session['ans'] del request.session['questionc'] messa = '答案修改成功' return render_to_response('message.html',{'message':messa})
def changeaddanswer(request):#修改增加 if 'origin' in request.GET and 'ques' in request.GET: orig = request.GET['origin'] ques = request.GET['ques'] request.session['questionc'] = ques request.session['ans'] = orig #return HttpResponse(chan) multiple_answer = Answer.objects.get(answer = orig) multiple_question = Questionans(question = ques) return render_to_response('changeaddans.html',{'answer':multiple_answer,'question':multiple_question}) if request.POST: ans = request.POST['answer'] anso = request.session.get('ans') ques = request.session.get('questionc') multiple_answer = Answer.objects.get(answer = anso) questionall = Question.objects.get(question = ques)# multiple_question = Questionans(question = ques) if (multiple_question): answers = multiple_question.answers.all() if multiple_answer in answers: multiple_question.answers.remove(multiple_answer)#之前回答过 multiple_answer.answer = ans else: multiple_answer = Answer(answer = ans,score = 60) else: multiple_answer = Answer(answer = ans,score = 60) multiple_answer.save() multiple_question = Questionans(question = ques)#添加到我的回答中 multiple_question.save() multiple_question.answers.add(multiple_answer) questionall.answers.add(multiple_answer)#添加到所有问题中 usern = request.session.get('username')#baoun user1 = User.objects.get(username = usern) user1.myanswers.add(multiple_question) del request.session['questionc'] del request.session['ans'] messa = '答案修改成功' return render_to_response('message.html',{'message':messa})
def addanswer(request): if 'ques' in request.GET: ques = request.GET['ques'] request.session['questiona'] = ques #return HttpResponse(chan) multiple_question = Questionans(question = ques) return render_to_response('addans.html',{'question':multiple_question}) if request.POST: ans = request.POST['answer'] multiple_answer = Answer(answer = ans,score = 60) multiple_answer.save() ques = request.session.get('questiona') multiple_question = Questionans(question = ques) multiple_question.save() multiple_question.answers.add(multiple_answer) questionall = Question.objects.get(question = ques)#tianjia jin suoyouwenti questionall.answers.add(multiple_answer) usern = request.session.get('username')#baoun user1 = User.objects.get(username = usern) user1.myanswers.add(multiple_question) del request.session['questiona'] messa = '答案添加成功' return render_to_response('message.html',{'message':messa})