Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
8022 มุมมอง

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
separate long name into several field แก้ไขแล้ว
1
มี.ค. 15
5551
0
มิ.ย. 15
3217
Concatenate two fields in a third one แก้ไขแล้ว
2
ส.ค. 24
2439
2
มิ.ย. 19
2951
0
มี.ค. 24
3397