如何在 oTree 中创建多项选择题?
How to create a multiple choice question in oTree?
我想知道在otree中是否可以做选择题。有点像单选按钮,但它可以让你选择不止一件事。
我在想的是这样的:
问题:下面的陈述列表包含三个正确的陈述和三个错误的陈述。请select三个正确的说法:
- 声明 1
- 声明 2
- 声明 3
- 声明 4
- 声明 5
- 声明 6
您可以使用 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 %}
我想知道在otree中是否可以做选择题。有点像单选按钮,但它可以让你选择不止一件事。 我在想的是这样的:
问题:下面的陈述列表包含三个正确的陈述和三个错误的陈述。请select三个正确的说法:
- 声明 1
- 声明 2
- 声明 3
- 声明 4
- 声明 5
- 声明 6
您可以使用 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 %}