本文整理汇总了Python中models.Vote.give_vote方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.give_vote方法的具体用法?Python Vote.give_vote怎么用?Python Vote.give_vote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.give_vote方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_poll_vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import give_vote [as 别名]
def api_poll_vote(request):
api_result = {"api": "poll_vote", "status": "success"}
try:
token = request.GET["token"]
user = get_user_from_token(token)
if not user:
api_result["status"] = "failure"
api_result["error"] = "user not found"
else:
question_id = request.GET["id"]
choice_id = request.GET["choice"]
question = Question.objects.get(pk=question_id)
choice = Choice.objects.get(pk=choice_id)
# user vote
Vote.give_vote(user, question, choice)
api_result["mychoice"] = choice.choice_text
api_result["choices"] = [
c.choice_text[:10] + ".." if len(c.choice_text) > 10 else c.choice_text
for c in question.choice_set.all()
]
api_result["votes"] = [c.votes for c in question.choice_set.all()]
except Exception as e:
api_result["status"] = "failure"
api_result["error"] = e.message
pass
return JsonResponse(api_result)
示例2: _vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import give_vote [as 别名]
def _vote(request):
question_id = request.GET["question_id"]
choice_id = request.GET["choice_id"]
print question_id, choice_id
question = Question.objects.get(pk=question_id)
choice = Choice.objects.get(pk=choice_id)
Vote.give_vote(request.user, question, choice)
context = {"question": question}
data = {}
data["mychoice"] = choice.choice_text
data["choices"] = [
c.choice_text[:10] + ".." if len(c.choice_text) > 10 else c.choice_text for c in question.choice_set.all()
]
data["votes"] = [c.votes for c in question.choice_set.all()]
# return render(request, 'polls/v1_poll_summary_small.html', context)
return JsonResponse(data)