oTree Forum >

PARTICPANT_FIELDS does not work

#1 by GregorFHSU

Hello everyone,

I try to randomize my treatment with this code. It is part of my first app, but doesn´t add the attribute "treatment" to my other apps so I can´t access "treatment" where I need it. I do have treatment in settings.py --> PARTICIPANT_FIELDS. 

class Player(BasePlayer):
    treatment = models.StringField()
    

class Intro(Page):
    form_model = 'player'
    @staticmethod
    def before_next_page(player: Player, timeout_happened):

        import random
        participant = player.participant
        participant.treatment = random.choice([True, False])
        
 Code from the other app:    
  
 class UnitsMix(Page):
    form_model = 'player'
    form_fields = ['units']
    @staticmethod
    def is_displayed(player: Player):
        return participant.treatment

    @staticmethod
    def app_after_this_page(player, upcoming_apps):
            return 'INFO'

class UnitsStraight(Page):
    form_model = 'player'
    form_fields = ['units']
    @staticmethod
    def is_displayed(player: Player):
        return not participants.treatment

    @staticmethod
    def app_after_this_page(player, upcoming_apps):
            return 'INFO'
       
               
 I also tried this code I found in Google Groups, but it doesn´t work either.
        
 def creating_session(subsession):
    # randomize to treatments
    if subsession.round_number == 1:
        for player in subsession.get_players():
            participant = player.participant
            print(participant)
            participant.treatment = random.choice([True,False])
            print(participant.treatment)
        
 Thank you in advance,
 Gregor

Write a reply

Set forum username