oTree Forum >

Accessing model field label and choices in __init.py__

#1 by ccrabbe

Let's say I have a Player field where I define a label and some choices, like for example:

class Player(BasePlayer):
    field_name = models.IntegerField(label='What is the answer to this question?',
Is there any way somewhere else in __init.py__ to access the values of field_name's label and choices?  I know that for choices I can store them in Constants and then set choices=Constants.field_name_choices or whatever. Is there a way to access these values otherwise?

Printing out Player.field_name.label gives me something like this instead of the value I want:

Player.field_name.label= <bound method QueryableAttribute.label of <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x00000238898CDA68>>


#2 by Chris_oTree

The only supported way is as you said - to store label and choices somewhere global like Constants, so that it can be referenced from elsewhere.

Write a reply

Set forum username