python - 如何在 oTree 中创建多项选择题?
问题描述
我想知道在 otree 中是否可以有多项选择题。类似单选按钮的东西,但它可以让你选择不止一件事。我在想的是这样的:
问题:以下陈述列表包含三个正确陈述和三个错误陈述。请选择正确的三个陈述:
- 声明 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 %}
推荐阅读
- java - Spring Boot Mongo Data org.springframework.data.mapping.context.InvalidPersistentPropertyPath
- c# - 带有更多参数的处理程序重新定义
- android - 用于构建自定义 Android 浏览器的 Webview 应用程序与 Chromium fork
- asp.net-core - 在 ASP.NET Core 中找到类似的方法 filterContext.ActionParameters
- postgresql - 使用参数调用 postgres 函数时关系不存在
- arrays - 为什么在 PowerShell 中使用逗号连接字符串?
- mobile - 移动浏览器错误:当顶部栏可见时,菜单链接无法正常工作
- python - 我如何编写代码来知道可被秒整除的整数?
- css - 什么是移动设备中的 CSS 像素?
- ionic-framework - 如何将自己的 svg 图标插入 ionic 6?