#1 by Veek
Hello, for my task, I needed the participant to enter a budget (budget_request) that not less than X amount, let's say 200 less than a budget (actual_budget) that is set for the group. I've used the code below, but am running into application errors (500) caused by the back-end of otree - Boolean value of this clause is not defined: "\Python\Python313\Lib\site-packages\sqlalchemy\sql\elements.py, line 3275, in __bool__". There are a about a dozen other locations listed in the error message but the one above is the top. I've checked my code and it works if I define the minimum for budget_request using a Constant.actual_budget but then it would assign the same random budget to every single group, which defeats the purpose of randomization. Any suggestions regarding a workaround? I've tried to define the budget_request at the player level and call Groups.actual_budget in the definition of the minimum, but it gives the same error. On a side note, I'm thinking that a possible solution could be to use the value of actual_budget, but I'm not sure which function to call in oTree to get the value attribute of a models.IntergerField() variable - i.e., how do I get something like actual_budget.value()? Also, is there a more detailed documentation page that allows me to look up the attributes of OTreeColumn objects? I think I can solve this issue if I can look how to call the value attribute of an OTreeColumn object. Thanks so much for reading. Relevant code follows: class Group(BaseGroup): #generate random actual budget for the group between 400 and 1000 actual_budget = models.IntegerField(initial=(random.randint(400,1000))) #define budget request variable for the budget request, must range from actual - 200 to max of 1000 budget_request = models.CurrencyField( label='What budget request would you like to submit?', min=((actual_budget - 200)), max=1000 )
#2 by woodsd42
I know this is an old post and you've probably figured this out already, but here's the most relevant link for your issue: https://otree.readthedocs.io/en/latest/forms.html#field-name-max And where you'd set the group's random budget, instead of in the group class initial=, you should do it in creating_session(): https://otree.readthedocs.io/en/latest/multiplayer/groups.html#group-like-round Except instead of the 'shuffling code' you would put in your budget randomization looping over subsession.get_groups(), and in the else statement you'd also loop over the groups but set the budget according to group.in_round(1). I think the issues you are having are mostly due to when otree executes code, and not doing things in the way that otree expects or is built for. If you haven't already, make sure you have followed the tutorial in the documentation, as well as refer to the documentation for standard ways to do things.