# Function field in table\_query

**URL:** https://discuss.tryton.org/t/function-field-in-table-query/4520
**Category:** Developer
**Created:** [August 5, 2021, 1:25pm UTC](https://discuss.tryton.org/t/function-field-in-table-query/4520 "2021-08-05T13:25:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![solenepetit](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@solenepetit](https://discuss.tryton.org/u/solenepetit)
#### Post date: [August 5, 2021, 1:25pm UTC](https://discuss.tryton.org/t/function-field-in-table-query/4520/1 "2021-08-05T13:25:46Z")

</div>

Hello again Tryton community !  
This topic is linked to [this one](https://discuss.tryton.org/t/displaying-a-group-by-list-as-a-model-field/4492) where I discussed on how to display a “group by” table in a tree view. I am trying to implement [this solution suggested by ced](https://discuss.tryton.org/t/displaying-a-group-by-list-as-a-model-field/4492/2), but I am experiencing some difficulty (I am new to Tryton).  
I would like to implement a model based on a table\_query, which would return the table of purchases group by party and the sum on the total\_amount column.

I noticed that I could not select the total\_amount field, because, as a function field, its value is not stored in the database, so there is no total\_amount column in the Purchase table.

My question is : what could I implement to manage to display the value of this field in my table\_query ? I tried to create a new field with an on\_change\_total\_amount method to store the value of total\_amount in a field stored in the database. But apparently I cannot base an on\_change method on a function field too…

So what could be a solution to display a function field in the list of a model based on a table\_query ?  
Thank you for your help, and sorry for the vocabulary mistakes if there are any.

---

<div class="post-metadata">

### Author: ![dave](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://discuss.tryton.org/u/dave)
#### Post date: [August 5, 2021, 8:41pm UTC](https://discuss.tryton.org/t/function-field-in-table-query/4520/2 "2021-08-05T20:41:57Z")

</div>

> [@solenepetit](#):
>
> what could I implement to manage to display the value of this field in my table\_query

As the value of this field is not stored in the database, you will need to add a function field to your model to calculate its value. Perhaps you can take some inspiration from: [https://hg.tryton.org/modules/sale/file/8848150a4586/sale\_reporting.py#l410](https://hg.tryton.org/modules/sale/file/8848150a4586/sale_reporting.py#l410)

If you only care about purchases that are confirmed, done, or cancelled, then you may be able to use the value in the `total_amount_cache` column from the database.
