Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
7978 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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') 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
5523
0
thg 6 15
3172
2
thg 8 24
2412
2
thg 6 19
2918
0
thg 3 24
3382