تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
7945 أدوات العرض

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
مارس 15
5463
0
يونيو 15
3137
2
أغسطس 24
2368
2
يونيو 19
2876
0
مارس 24
3339