oTree Forum >

Errors with get_form_fields

#1 by Iris

Hi Chris,

I would like to show the fields dynamically based on a participant variable stored from the previous app, and I got some issues with the get_form_fields() function. The error message is "group has no attribute 'U'." Could you please help me with this? Thanks very much!

In Pages.py, I wrote:

class Decision_Row_re(Page):
    def is_displayed(self):
        return self.player.participant.vars['groupid'] == 1 and self.player.participant.vars['realized'] == 1

    form_model = 'group'
    def get_form_fields(self):
        if self.player.participant.vars['realized'] == 0:
            return ['U', 'M', 'D']
            return['U', 'M']
In models, I defined:

class Group(BaseGroup):
    player1_decision = models.StringField(choices=['U', 'M','D'], label="")

Best regards,

#2 by Victor


I'm not 100% sure this helps, but I suspect "get_form_fields" can help determine the variables you'd like to include dynamically. However, you are trying to extract the choices of one variable dynamically. Under your Page class, oTree has no way of knowing that you're referring to "player1_decision." Thus, perhaps you could try creating two variables and use "get_form_fields" to dynamically select among them.


#3 by Iris

Hi Victor,

Thanks very much for your kind reply. I have figured it out. 


Write a reply

Set forum username