How to access data from custom_export in Otree?

Question:

I am trying to use ExtraModel and custom_export to export data from live_pages. However, when I go on devserver and check the data tab, it is nowhere to be found. If I download the excel (bottom right of the page) the new variables are not included in the data.

Where can I find the data from the custom export? Or am I defining the function wrong? Any help greatly appreciated.

enter image description here

See MWE below

from otree.api import *
import random

doc = """
Your app description
"""


class C(BaseConstants):
    NAME_IN_URL = 'mwe_export'
    PLAYERS_PER_GROUP = None
    NUM_ROUNDS = 1
    NUM_EMPLOYERS = 3


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    pass


class Player(BasePlayer):
    pass


class Offer(ExtraModel):
    group = models.Link(Group)
    sender = models.Link(Player)
    wage = models.IntegerField()
    effort = models.IntegerField()
    job_id = models.IntegerField()
    information_type = models.StringField()


# FUNCTIONS
def to_dict(offer: Offer):
    return dict(sender=offer.sender.id_in_group,
                wage=offer.wage,
                effort=offer.effort,
                job_id=offer.job_id,
                information_type=offer.information_type)


# PAGES
class MyPage(Page):
    @staticmethod
    def js_vars(player: Player):
        return dict(my_id=player.id_in_group)

    @staticmethod
    def live_method(player: Player, data):
        print(data)
        group = player.group
        job_id = random.randint(1, 1000)
        wage = data['wage']
        effort = data['effort']
        information_type = data['information_type']

        if data['information_type'] == 'offer':
            offer = Offer.create(group=group,
                                 sender=player,
                                 job_id=job_id,
                                 wage=wage,
                                 effort=effort,
                                 information_type=information_type)
            print(offer)
            print(to_dict(offer))
            return {0: to_dict(offer)}


page_sequence = [MyPage]


def custom_export(players):
    yield ['session.code', 'participant_code', 'id_in_session']
    offers = Offer.filter()

    for offer in offers:
        player = offer.sender
        participant = player.participant
        yield [participant.code, participant.id_in_session, offer.job_id, offer.wage, offer.effort]
Asked By: Papayapap

||

Answers:

In the menu at the top of the admin page there is also a "Data" item. The custom export for your app should be available there under the heading "Per-app".

Answered By: davidlucius
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.