콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
9707 화면

I want to use a Many2one field that relates n cases with 1 investigator:

assigned_investigator = fields.Many2one('ufodata.investigator', string='Assigned Investigator')

From investigator, I want to specify a field "user_name" as related field of the many2one relation:

assigned_investigator = fields.Many2one('ufodata.investigator', string='Assigned Investigator', related='???')

In the Investigator model, the field is defined as user_name = fields.Char()
Now I'm missing the correct notation to specify the related field:

related='ufodata.investigator.user_name' --> KeyError: 'ufodata'
related='investigator.user_name' --> KeyError: 'investigator'
related='Investigator.user_name' --> KeyError: 'Investigator'
related='user_name' --> KeyError: 'user_name'
related='ufodata.investigator_id.user_name' --> KeyError: 'ufodata'
related='investigator_id.user_name' --> KeyError: 'investigator_id'

do all not work. What I am doing wrong?

아바타
취소

bill_id = fields.Many2one('model.one','Bill Ref')

bill_batch_id = fields.Many2one(related='bill_id.bill_batch_id', string="Batch Ref.")

작성자 베스트 답변

To make my problem more clear: I've got a Many2one field from (many) cases to (one) investigator. This field is a link to the assigned investigator dataset, but the text of the link is not any value of the dataset, but "ufodata.investigator,1", i.e. the type combined with an id (can't add screenshots here). Of course, I do not want this, but the name of the investigator. I can help myself with adding a related field that extracts one the investigator's values (user_name), but then I've got only a label, not a link (or combo box in edit mode). I want to have the link, but with a value representing the linked dataset.

Edit: question has been answered here: https://www.odoo.com/de_DE/forum/hilfe-1/question/representation-of-many2one-in-view-163488

아바타
취소
베스트 답변

The example is a bit confusing. The name of the second field (assigned_investigator) in your example is the same as the first field (assigned_investigator). Shouldnt the second field be called assigned_investigator_name or something similar ?

아바타
취소
작성자

Yes, it's confusing, sorry! It was meant only as two versions of the same line of code, without and with the "related" parameter. Without the parameter, the Many2One field is represented in the view by a "<type>,<id>" tuple, e.g. "ufodata.investigator,1". Now I want the investigator's name instead of this tuple, and as I understand it, this should be achieved by applying the "related" parameter.

You will need to define 2 fields - a Many2one for the id (for example investigator_id) and the other for the name (for example investigator_name). investigator_name will have to be declared with a related=investigator_id.user_name

관련 게시물 답글 화면 활동
4
1월 20
3480
0
11월 18
4740
0
4월 17
4046
1
1월 25
2420
3
10월 22
6283