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


Python Answer.ans_sub方法代码示例

本文整理汇总了Python中models.Answer.ans_sub方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.ans_sub方法的具体用法?Python Answer.ans_sub怎么用?Python Answer.ans_sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Answer的用法示例。


在下文中一共展示了Answer.ans_sub方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: submit

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import ans_sub [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!")
开发者ID:jmend736,项目名称:putz-sup,代码行数:66,代码来源:views.py


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