我有下一个代码。我想计算李克特量表中每个选项的响应数。我有一个通用模型表单,它只保存每个参与者的响应,但不计算所有参与者的响应总数。我需要为每个问题和量表上的每个项目生成结果。例如,对于下面的代码段,总响应应该有 8 个空格。(每题4题,共2题)
这是我的模型中针对李克特量表的每个问题的代码:
class Group(BaseGroup):
def set_payoffs(self):
players = self.get_players()
sumPoints_e11a = [p.Points_e11a for p in players]
sumPoints_e11b = [p.Points_e11b for p in players]
sumPoints_e11c = [p.Points_e11c for p in players]
sumPoints_e11d = [p.Points_e11d for p in players]
self.Pointsa = sum(sumPoints_e11a)
self.Pointsb = sum(sumPoints_e11b)
self.Pointsc = sum(sumPoints_e11c)
self.Pointsd = sum(sumPoints_e11d)
class Group(BaseGroup):
eleccion1 = models.PositiveIntegerField(
choices=[[-3, "Muy Socialmente Inapropiado"],
[-1, "Muy Socialmente Inapropiado"],
[ 1, "Algo Socialmente Apropiado" ],
[ 3, "Muy Socialmente Apropiado" ]
],
widget=widgets.RadioSelect
)
eleccion2 = models.PositiveIntegerField(
choices=[[-3, "Muy Socialmente Inapropiado"],
[-1, "Muy Socialmente Inapropiado"],
[1, "Algo Socialmente Apropiado"],
[3, "Muy Socialmente Apropiado"]
],
widget=widgets.RadioSelect
)
这是我的 Page.py 代码
class situaciond1(Page):
form_model = 'player'
form_fields = ['e11','e12','e13','e14','e15','e16', ]
def before_next_page(self):
for p in self.group.get_players():
if p.e11 == -3:
g.Points_e11a += 1
if p.e11 == -1:
g.Points_e11b += 1
if p.e11 == 1:
g.Points_e11c += 1
if p.e11 == 3:
g.Points_e11d += 1
if p.e12 == -3:
g.Points_e12a += 1
if p.e12 == -1:
g.Points_e12b += 1
if p.e12 == 1:
g.Points_e12c += 1
if p.e12 == 3:
g.Points_e12d += 1
if p.e13 == -3:
```
这是我的 html 代码,我使用子索引来调用未来每个项目的响应。
<table class="tg">
<tr>
<th class="tg-mqa1">Elecciones Individuo A</th>
<th class="tg-mqa1">Muy Socialmente Inapropiado</th>
<th class="tg-mqa1">Algo socialmente Inapropriado</th>
<th class="tg-mqa1">Algo socialmente Apropriadp</th>
<th class="tg-mqa1">Muy Socilamente Apropiado</th>
</tr>
<tr>
<td class="tg-wp8o"><span style="font-weight:bold">Tomar $COP 5 del Individuo B</span> <br> (Individuo A obtiene $COP 10, Individuo B obtiene $0)</td>
<td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
<td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
<td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
<td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
</tr>
<tr>
<td class="tg-wp8o"><span style="font-weight:bold">Tomar $COP 5 del Individuo B</span> <br>(Individuo A obtiene $COP 10, Individuo B obtiene $0)</td>
<td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
<td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
<td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
<td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
</tr>
<tr>