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

if I have this :

task_field = fields.Many2one('project.task', 'task_id', required=True)

How can I use this field, the task_field - task_id in a function:


def do(self):

   #task_field task_id 


any help?

아바타
취소
베스트 답변

 syntax of Many2one field is:

field_name = fields.Many2one(comodel_name=None, string=None, **kwargs)

---Example of access class field use into its function

def function_name(self):

   print self.field_name.


Hope this help

아바타
취소
작성자

what I need to do with this co_model_name=???

that fields relate with which model like as per your example you can set project.task as co_model_name

베스트 답변

Wizardz,

To access any field you have to use its objects reference to access that fields value..

you can do something like this,

@api.multi #in case of api.multi decorator

def do(self):

    for obj in self:

        print obj.task_field # here is your field


@api.one # in case of api.one decorator

def do(self):

       print self.task_field # here is your field

아바타
취소
작성자

when I do your example, it doesn't find my field task_field

관련 게시물 답글 화면 활동
3
9월 21
9485
1
2월 21
4988
4
1월 20
3297
0
11월 18
4534
0
4월 17
3748