当前位置: 首页>>代码示例>>Python>>正文


Python Vote.give_vote方法代码示例

本文整理汇总了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)
开发者ID:krdeepak,项目名称:djmysite,代码行数:32,代码来源:views.py

示例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)
开发者ID:krdeepak,项目名称:djmysite,代码行数:24,代码来源:views.py


注:本文中的models.Vote.give_vote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。