oTree Forum >

(Variable Length) List of Fields

#1 by cybervision

I'm trying to create a certain player field for each round, so that there is a separate "guess" field for each round. At the moment it's hard coded (e.g. guess1 = models.CurrencyField(), guess2 = models.CurrencyField(), ...), but I would prefer to have a list object of guesses so that I can easily change the number of rounds. 

How can I create a list of guess objects, called e.g. "guesses" that I can make flexibly depend on the number of rounds?

I tried:

    guesses = [models.CurrencyField(min=0,max=10,label = str(i)) for i in range(C.NUM_ROUNDS)]
 but oTree didn't like that.

#2 by Chris_oTree

If you have multiple rounds, then you can reuse the same field -- there's no need to create multiple fields. Each round has a separate Player object.

#3 by cybervision

The issue is, at the start, I want participants to guess the result that will occur at each future round. So if there are 10 rounds, I want a guess for the result of round 1, a guess for the results of round 2, round 3, round 4, etc. 

The goal is to set payoffs at the end that depend on the accuracy of their guesses...for that I need to keep track of their distinct guess for each future round.

#4 by Chris_oTree

OK I see. You can use an ExtraModel for that kind of flexibility. But actually the hardcoded solution you have currently seems OK to me. With ExtraModel, you need some extra code to produce the form field, connect it to the ExtraModel, etc.

Write a reply

Set forum username