我想让参与者不能竞标超过剩余资金。如果前三轮都投了30,下一轮投不超过110。(200-3*30)
运行此程序时我没有收到任何错误,但验证不起作用,错误消息没有弹出。即使第一次投资出价超过200。
我希望为所有轮次编制的总投标不应超过最初给出的预算。
请帮忙
class Constants(BaseConstants):
name_in_url = 'C'
players_per_group = None
num_rounds = 18
budget = 200
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
invest = models.IntegerField(
label="How much would you like to invest in this proposal?",
min=0
)
total_invest = models.IntegerField()
# PAGES
class MyPage(Page):
form_model = 'player'
form_fields = ['invest']
@staticmethod
def total_invest(player: Player):
player_in_all_rounds = player.in_all_rounds()
return sum([p.invest for p in player_in_all_rounds])
@staticmethod
def avail_invest(player: Player):
return Constants.budget - player.total_invest
@staticmethod
def invest_error_message(player, value):
print('value is', value)
if value > player.avail_invest:
return 'Cannot invest more than your remaining fund'
class ResultsWaitPage(WaitPage):
pass
**strong text**
class Results(Page):
pass
page_sequence = [MyPage]