如何在oTree中创建选择题?

时间:2018-07-19 10:19:29

标签: python multiple-choice otree

我想知道在otree中是否可能有一个选择题。单选按钮之类的东西,但是您可以选择多个。 我在想的是这样的:

问题:以下语句列表包含三个正确的语句和三个错误的语句。请选择三个正确语句:

  • 声明1
  • 声明2
  • 声明3
  • 声明4
  • 声明5
  • 声明6

1 个答案:

答案 0 :(得分:0)

为此,您可以使用otree_models.models.MultipleChoiceFormField,如下所示:

models.py中:

from otree.api import BasePlayer
from otree_tools.models import fields as tool_models

class Player(BasePlayer):

    correct_statements = tool_models.MultipleChoiceModelField(label="Please select the three correct statements",
                                                              min_choices=3, max_choices=3)

pages.py中:

from ._bultin import Page

class ExamplePage(Page):

    form_model = "player"
    form_fields = ["correct_statements"]

    def correct_statements_choices(self):
         """Return the list of statements to choose from."""
         return ["Statement 1", "Statement 2", "Statement 3",
                 "Statement 4", "Statement 5", "Statement 6"]

ExamplePage.html中,只需包含表单字段:

{% extends "global/Page.html" %}
{% load otree %}

{% block content %}
The following list of statements contains three correct statements and three false statements. 

{% formfield player.correct_statements %}

{% next_button %}

{% endblock %}