On the page where you want to display the average, add the function vars_for_template(), something like this:
class MyPage(Page):
def vars_for_template(self):
player = self.player
average = (player.income1 + player.income2 + player.income3) / 3
return dict(average_value = average)
Then in your HTML on that page, write {{ average_value }} where you want your average to appear.
Good luck,
Rok
unsupported operand type(s) for +: 'NoneType' and 'NoneType' |
class InstructionsA(Page):
form_model = 'player'
form_fields = ['income1',
'income2',
'income3',
]
def is_displayed(self):
return self.round_number == 1
def vars_for_template(self):
player = self.player
average = (player.income1 + player.income2 + player.income3) / 3
return dict(average_value = average)
My html
<table class="table-bordered" style="width:100%">
<tr style="background-color:#ffb380">
<th scope="col" colspan="1" style="text-align:center"> Anno </th>
<th scope="col" colspan="1" style="text-align:center"> 2018 - 2019 </th>
<th scope="col" colspan="1" style="text-align:center"> 2019 - 2020 </th>
<th scope="col" colspan="1" style="text-align:center"> 2020 - 2021 </th>
<th scope="col" colspan="1" style="text-align:center"> MEDIA </th>
</tr>
<tr style="background-color:#ffe0cc">
<td scope="col" colspan="1" style="text-align:center"> Reddito/ettaro </td>
<td> <input type="number" name="income1" min="0" > €/ha</td>
<td> <input type="number" name="income2" min="0" > €/ha</td>
<td> <input type="number" name="income3" min="0" > €/ha</td>
<td> {{ average_value }} €/ha</td>
</tr>
</table>
---------------------------------------------------------------------------------------------------------------------------
--
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/J_z7Siw16Ro/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/5bcde743-f1d7-48c7-aed4-413a4f3c94c6n%40googlegroups.com.
