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


Python Answer.question方法代码示例

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


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

示例1: set_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import question [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()
开发者ID:ChickTech,项目名称:puzzle-hunt,代码行数:29,代码来源:flask_app.py

示例2: _saveable_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import question [as 别名]
 def _saveable_answer(self, ans=None):
     if ans is None:
         ans = Answer()
     ans.question = self.question
     ans.session_key = self.session_key
     if self.user.is_authenticated():
         ans.user = self.user
     else:
         ans.user = None
     ans.interview_uuid = self.interview_uuid
     return ans
开发者ID:bearstech,项目名称:Django-survey,代码行数:13,代码来源:forms.py

示例3: question

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

示例4: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import question [as 别名]
 def save(self, commit=True):
     if not self.cleaned_data['answer']:
         if self.fields['answer'].required:
             raise ValidationError, _('This field is required.')
         return
     ans_list = []
     for text in self.cleaned_data['answer']:
         ans = Answer()
         ans.question = self.question
         ans.session_key = self.session_key
         ans.text = text
         if commit: ans.save()
         ans_list.append(ans)
     return ans_list
开发者ID:scanner,项目名称:my-django-survey,代码行数:16,代码来源:forms.py

示例5: add_new_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import question [as 别名]
def add_new_answer(request):
    _check_for_admin()
    post = request.POST
    if post:
        new_answer = post["new_answer"]
        new_link = post["new_link"]
        new_date = datetime.strptime(post["date"], "%d.%m.%Y").date()
        new_question = get_question()
        answer = Answer()
        answer.text=new_answer
        answer.more_link = new_link
        answer.question=new_question
        answer.date = new_date
        answer.save()
    return redirect("polls.views.main_page")
开发者ID:soswow,项目名称:yet-another-one-poll-on-app-engine,代码行数:17,代码来源:views.py

示例6: save

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import question [as 别名]
 def save(self, commit=True):
     if not self.cleaned_data["answer"]:
         if self.fields["answer"].required:
             raise ValidationError, _("This field is required.")
         return
     ans_list = []
     for text in self.cleaned_data["answer"]:
         ans = Answer()
         ans.question = self.question
         ans.session_key = self.session_key
         if self.user.is_authenticated():
             ans.user = self.user
         else:
             ans.user = None
         ans.interview_uuid = self.interview_uuid
         ans.text = text
         if commit:
             ans.save()
         ans_list.append(ans)
     return ans_list
开发者ID:StelaDD,项目名称:survey,代码行数:22,代码来源:forms.py


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