本文整理汇总了Python中models.Answer.value方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.value方法的具体用法?Python Answer.value怎么用?Python Answer.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Answer
的用法示例。
在下文中一共展示了Answer.value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_answer
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import value [as 别名]
def set_answer(puzzle_name, player_id, question, content_type, content):
player = Player.get(Player.id == player_id)
puzzle, _ = Puzzle.get_or_create(name=puzzle_name)
try:
answer = Answer.get(
(Answer.puzzle == puzzle) & (Answer.player == player))
except Answer.DoesNotExist:
answer = Answer(puzzle=puzzle, player=player)
answer.question = question
if content_type == 'text':
answer.value = content
elif content_type == 'image':
filename = '%s_%s.jpg' % (puzzle.id, player.id)
path = '%s/images/%s' % (STATIC_DIR, filename)
with open(path, 'wb') as fp:
fp.write(content)
answer.value = 'image:' + filename
elif content_type == 'video':
filename = '%s_%s.mp4' % (puzzle.id, player.id)
path = '%s/videos/%s' % (STATIC_DIR, filename)
with open(path, 'wb') as fp:
fp.write(content)
answer.value = 'video:' + filename
answer.save()
示例2: question
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import value [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: experiment_page
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import value [as 别名]
def experiment_page(request):
participant_id = request.session['participant_id']
if not participant_id:
return HttpResponseRedirect("/")
# Get participant & an image set ID that we don't have yet.
participant = Participant.objects.get(id=participant_id)
if not participant:
return Http404()
if request.method == "GET":
answers_count = participant.answer_set.count()
image_sets = {x.imageSet_id for x in participant.answer_set.all()}
total_set = {x for x in range(1, 61)}
allowed = total_set.difference(image_sets)
if len(allowed) > 0:
random.seed()
idx = random.sample(allowed, 1)[0]
next_set = ImageSet.objects.get(id=idx)
if not next_set:
return HttpResponseServerError(content="No image set found")
# TODO : Add "which" parameter
data = {"image_set": next_set,
"num_images": "two" if participant.num_images is 2 else "three"}
return render_to_response("entry.html",
data,
context_instance=RequestContext(request))
else:
return HttpResponseRedirect("/survey")
elif request.method == "POST":
answer = Answer()
answer.user = participant
answer.imageSet_id=int(request.POST["image-set-id"])
answer.value = int(request.POST["dollar-value"])
# TODO : Add "which" parameter
answer.save()
return HttpResponseRedirect("/experiment")