oTree Forum >

pass data across apps

#1 by LC01063

Hi,

I designed a survey with three rounds in one app, and I want to pass all the data to another app. I was able to collect  data from previous rounds into one list but I don't know how to pass it or set up the participant field. Can anyone help with that? Thanks.

This is my first app:

from otree.api import *

class C(BaseConstants):
    NAME_IN_URL = 'pictures'
    PLAYERS_PER_GROUP = None
    NUM_ROUNDS = 3

class Subsession(BaseSubsession):
    pass

class Group(BaseGroup):
    pass

class Player(BasePlayer):
    q = models.BooleanField(
        label='Do you like this picture?',
        choices=[
            [True, 'Yes'],
            [False, 'No'],
        ]
        )

# PAGES
class Instructions(Page):
    def is_displayed(player):
        return player.round_number == 1

class Questions(Page):
    form_model = 'player'
    form_fields = ['q']
    @staticmethod
    def before_next_page(player: Player, timeout_happened):
        all_players = player.in_all_rounds()
        # player.participant.all_players = player.all_players
        # print(all_players)

page_sequence = [Instructions, Questions]

And here is my next app:

from otree.api import *

class C(BaseConstants):
    NAME_IN_URL = 'pictures'
    PLAYERS_PER_GROUP = None
    NUM_ROUNDS = 3

class Subsession(BaseSubsession):
    pass

class Group(BaseGroup):
    pass


class Player(BasePlayer):
    q = models.BooleanField(
        label='Do you like this picture?',
        choices=[
            [True, 'Yes'],
            [False, 'No'],
        ]
        )

# PAGES
class Instructions(Page):
    def is_displayed(player):
        return player.round_number == 1

class Questions(Page):
    form_model = 'player'
    form_fields = ['q']
    @staticmethod
    def before_next_page(player: Player, timeout_happened):
        all_players = player.in_all_rounds()
        # player.participant.all_players = player.all_players
        print(all_players)

page_sequence = [Instructions, Questions]

#2 by BonnEconLab

I assume that you would like to pass on the responses collected via the player field q to the subsequent app. If this is the case, the following should work:

In your settings.py, add something like

PARTICIPANT_FIELDS = ['collected_responses']

In your __init__.py, include

class Questions(Page):

    form_model = 'player'
    form_fields = ['q']

    @staticmethod
    def before_next_page(player, timeout_happened):
        if player.round_number == 1:
            player.participant.collected_responses = [player.q]
        else:
            player.participant.collected_responses.append(player.q)

Write a reply

Set forum username