# How to get other model data using foreign key

**URL:** https://discuss.tryton.org/t/how-to-get-other-model-data-using-foreign-key/3646
**Category:** Developer
**Created:** [January 5, 2021, 9:23am UTC](https://discuss.tryton.org/t/how-to-get-other-model-data-using-foreign-key/3646 "2021-01-05T09:23:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![athelia](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@athelia](https://discuss.tryton.org/u/athelia)
#### Post date: [January 5, 2021, 9:23am UTC](https://discuss.tryton.org/t/how-to-get-other-model-data-using-foreign-key/3646/1 "2021-01-05T09:23:57Z")

</div>

I have 2 model which is linked via a foreign key.

For example:

> class UserRegistration  
> age= fields.Text(‘Age’)

> class RoomBooking  
> user= fields.Many2One(‘user.registration’, ‘User’)

I want to display the user age in RoomBooking tree, is there any way to do so?  
I tried something like `<tree><field name="user.age" /></tree>` but error…  
Thank you.

---

<div class="post-metadata">

### Author: ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)
#### Post date: [January 5, 2021, 3:22pm UTC](https://discuss.tryton.org/t/how-to-get-other-model-data-using-foreign-key/3646/2 "2021-01-05T15:22:39Z")

</div>

You should create a function field “age” in your RoomBooking class with an “on\_change\_with”

See example here with company field: [https://hg.tryton.org/modules/sale/file/tip/sale.py#l1138](https://hg.tryton.org/modules/sale/file/tip/sale.py#l1138)

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [February 4, 2021, 3:22pm UTC](https://discuss.tryton.org/t/how-to-get-other-model-data-using-foreign-key/3646/3 "2021-02-04T15:22:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
