跳至內容
選單
此問題已被標幟
3 回覆
7942 瀏覽次數

hi, i m read this documentation. and found the related field so i want to understand actually how to use related field in country->state->city example.

頭像
捨棄

you want to fetch country name from state->country?

最佳答案

I normally use related fields only if I need some value from a parent model (M2O) to use it a view. Like when using domain filters, making fields invisible/readonly, itd.. Else just use M2O fields. Even with related fields you need a M2O field to use it in relate. 

For your example I think you can't the way you want. The res_country_state model has the country_id, so you could get the country name from the res_country_state model and not the other way around. 

country_name = fields.Char(relate='country_id.name') 

頭像
捨棄
最佳答案

You do not need to create related field you just use many2one field to access it.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
3月 15
5458
0
6月 15
3134
2
8月 24
2364
2
6月 19
2875
0
3月 24
3336