oTree Forum >

Problem with model fields

#1 by henning99

So I have a Boolean Field and a Integer Field. The boolean field stores the decision to enter the market and the interger field stores the player ID of the expert chosen:

# Model Fields
chosen_expert_id = models.IntegerField(null=True)
decision_made = models.BooleanField(initial=False)

# Code for page
class KonsumentenEntscheidung(Page): # Konsumenten wählen Angebote der Experten
    form_model = 'player'
    form_fields = ['market_entry', 'chosen_expert_id']

    @staticmethod
    def is_displayed(player):
        return player.ind_rolle == "Konsument"
    
    @staticmethod
    def vars_for_template(player: Player):
        experten = []
        for p in player.get_others_in_group():
            if p.ind_rolle == "Experte":
                experten.append({
                    'id_in_group': p.id_in_group,
                    'preis_kleine_dienstleistung': p.preis_kleine_dienstleistung,
                    'preis_grosse_dienstleistung': p.preis_grosse_dienstleistung,
                    'konsumenten_profit_klein': C.NUTZEN_KDL - p.preis_kleine_dienstleistung,
                    'konsumenten_profit_gross': C.NUTZEN_GDL - p.preis_grosse_dienstleistung,
                })
        return dict(experten=experten)

    @staticmethod
    def before_next_page(player: Player, timeout_happened):
        if player.market_entry == False:
            player.konsument_prof_kdl = 0
            player.konsument_prof_gdl = 0
            player.konto += 1
        else:
            chosen_expert_id = player.chosen_expert_id
            chosen_expert = player.group.get_player_by_id(chosen_expert_id)
            player.konsument_prof_kdl = C.NUTZEN_KDL - chosen_expert.preis_kleine_dienstleistung
            player.konsument_prof_gdl = C.NUTZEN_GDL - chosen_expert.preis_grosse_dienstleistung
        player.decision_made = True
        
I also attached the respective html file. Now the problem is that, when the consumers reach the decision side to decide which expert to choose and they click on either "choose expert" or "don't enter the market" the debug info shows:

(clicking on "choose expert)

The form field market_entry has errors, but its error message is not being displayed, possibly because you did not include the field in the template. There are 2 ways to fix this:

    Include the field with the formfield tag, e.g. {{ formfield "market_entry" }}
    If you are not using formfield but are instead writing the raw HTML for the form input, remember to include {{ formfield_errors 'market_entry' }} somewhere in your page's HTML.

and (clicking on "don't enter market"):


The form field chosen_expert_id has errors, but its error message is not being displayed, possibly because you did not include the field in the template. There are 2 ways to fix this:

    Include the field with the formfield tag, e.g. {{ formfield "chosen_expert_id" }}
    If you are not using formfield but are instead writing the raw HTML for the form input, remember to include {{ formfield_errors 'chosen_expert_id' }} somewhere in your page's HTML.

Maybe someone can help me :)

#2 by Fanist

Hi, according to the error, have you included ` {{ formfields }}` in your Page code? You should do that to let the page display the two questions.

Write a reply

Set forum username