本文整理汇总了Python中models.Answer.ans_text方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.ans_text方法的具体用法?Python Answer.ans_text怎么用?Python Answer.ans_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Answer
的用法示例。
在下文中一共展示了Answer.ans_text方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import ans_text [as 别名]
def submit(request):
"""
Submit a response
"""
if request.method == "POST":
for quest in request.POST:
if quest != "csrfmiddlewaretoken":
# Get answer to form
ans = request.POST[quest]
if ans:
# TODO: Allow input of a list of names
# Filter the response
filtered_ans = ans.lower().strip()
# Map to putzen kerberos
try:
putzen = Putzen(filtered_ans).name
except KeyError:
putzen = ans
# Try to increment previous answer
try:
# Get previous answer
prev_answer = Answer.objects.filter(
ans_text=putzen
).get(
ans_quest__quest_text=quest
)
# Incremement the counter
prev_answer.ans_count += 1
# Save the model to database
prev_answer.save()
except Answer.DoesNotExist:
# If you can't then create a new answer object
# Make new answer object
a = Answer()
# TODO: Save the submitter
a.ans_sub = "admin"
a.ans_count = 1
a.ans_text = putzen
# Update the Answers to Seleted Questions
i = Question.objects.get(quest_text=quest)
# Set the ForeignKey
a.ans_quest = i
# Write to database
a.save()
return HttpResponseRedirect('/vote/list/')
else:
# TODO: Make this page
return HttpResponse("You stumbled across the wrong page!")