本文整理汇总了Python中models.Question.text方法的典型用法代码示例。如果您正苦于以下问题:Python Question.text方法的具体用法?Python Question.text怎么用?Python Question.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import text [as 别名]
def create(request):
if request.method == "GET":
return render(request,'question/create.html',{})
q = Question()
q.title = request.POST["title"]
q.text = request.POST["text"]
q.save()
return redirect('lookup',q.id)
示例2: question
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import text [as 别名]
def question(request):
if request.method == 'GET':
# zasad koristim page parametar za jedno pitanje (id)
# page = request.GET['page']
question_number = request.GET['page']
questions_per_page = 2
question = Question.objects.get(number=question_number)
answers = question.answer_set.all()
return render(request, 'prikaz.html', { 'question': question, 'answers': answers })
elif request.method == 'POST':
question = Question()
post_data = request.POST;
try:
question.image = request.FILES['image']
except:
pass
question.answer_type = AnswerType.objects.get(name = post_data['type'])
question.text = post_data['text']
question.number = post_data['number']
question.save()
answers = []
print post_data
for key in [x for x in post_data if x.startswith('answer')]:
current = key.replace('answer', '')
post_answer = post_data['answer' + current]
post_solution = post_data['solution' + current]
if post_answer != '':
answer = Answer()
answer.text = post_answer
answer.value = post_solution
answer.question = question
answers.append(answer)
for answer in answers:
answer.save()
answer_types = AnswerType.objects.all()
return render(request, 'unos.html', \
{ 'question_number': int(question.number) + 1, \
'answer_types': answer_types })
else:
return HttpResponse("Method not allowed.", status=405)
示例3: post_answer
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import text [as 别名]
def post_answer():
data = {}
if request.form['question']:
question = Question()
question.text = request.form['question']
db.session.add(question)
db.session.commit()
answer = Answer.query.all()
if answer:
answer = choice(answer)
data['answer'] = answer.text
return jsonify(data)
else:
data['error'] = _('question is missing')
return jsonify(data), 400