0

您好,我有下一个代码可以向我的参与者显示在前面的会话中给我的响应文本。

    J11 = models.IntegerField(
        choices=[
            [-2, 'Muy moralmente inapropiado'],
            [-1, 'Moralmente inapropiado'],
            [0, 'No aplica'],
            [1, 'Moralmente apropiado'],
            [2, 'Muy moralmente apropiado'],
        ],
        widget=widgets.RadioSelect
    )
    TJ11 = models.CharField(max_length=2, choices=J11)

当我尝试证明此代码时,出现下一个错误:

File "C:\Users\diese\iat\incentivos\models.py", line 140, in <module>
 class Player(BasePlayer):
File "C:\Users\diese\iat\incentivos\models.py", line 216, in Player
 TJ11 = models.CharField(max_length=2, choices=J11)
File "c:\users\diese\appdata\local\programs\python\python37\lib\site-packages\otree\db\models.py",   line 386, in __init__super().__init__(max_length=max_length, **kwargs)
File "c:\users\diese\appdata\local\programs\python\python37\lib\site-packages\otree\db\models.py", line 217, in __init__
fix_choices_arg(kwargs)
File "c:\users\diese\appdata\local\programs\python\python37\lib\site-packages\otree\db\models.py",   line 195, in fix_choices_arg
choices = expand_choice_tuples(choices)
File "c:\users\diese\appdata\local\programs\python\python37\lib\site- packages\otree\common_internal.py", line 118, in expand_choice_tuples
if not isinstance(choices[0], (list, tuple)):
TypeError: 'IntegerField' object is not subscriptable

我能做些什么?有人有过同样的经历吗?

提前致谢

4

1 回答 1

0

您可以在定义字段之前定义选项,然后将这些选项分配给字段。这允许您将这些选择分配给多个字段:

MY_CHOICES = (
    (-2, 'Muy moralmente inapropiado'),
    (-1, 'Moralmente inapropiado'),
    (0, 'No aplica'),
    (1, 'Moralmente apropiado'),
    (2, 'Muy moralmente apropiado'),
)
J11 = models.IntegerField(choices=MY_CHOICES)
TJ12 = models.CharField(max_length=20, choices=MY_CHOICES)
于 2019-10-10T23:18:36.170 回答