oTree Forum >

Real-world currency saved in CurrencyField gets displayed as Points in template later on

#1 by gmdcastillo (edited )

Hi all,

I'm facing the following issue. Maybe it's me who doesn't understand how currencies are represented in oTree:

I have total payoffs in points

`participant.payoff = total_payoff`

which I want to save in the database as real-world money, so I create a field

`total_payoff_in_money = models.CurrencyField()`

and do

`player.total_payoff_in_money = total_payoff.to_real_world_currency(player.session)`

When I print it in the Terminal with 

`print('player.total_payoff_in_money: ', player.total_payoff_in_money)`

I get, as expected, 

"player.total_payoff_in_money:  £8.5"

On the page where I compute these, `{{ player.total_payoff_in_money }}` does show "£8.5". So far so good.

But in the next page, when in the template I do

`{{ player.total_payoff_in_money }}`

then I get

"8 points"

It seems oTree goes back to points without me using |cu. Is there something I'm missing?

#2 by Chris_oTree ,

CurrencyField is for points if you set USE_POINTS=True, or real world currency otherwise. If you want to store something else, use integer or float field. The inconsistent behavior you’re seeing may be because it’s before vs after the data gets saved in the DB.

#3 by gmdcastillo

OK I see, that makes sense. Thanks for the clarification!

Write a reply

Set forum username