コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
9284 ビュー

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
9396
1
2月 21
4908
4
1月 20
3207
0
11月 18
4440
0
4月 17
3661