Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
9278 Prikazi

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?

Avatar
Opusti
Best Answer

 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

Avatar
Opusti
Avtor

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

Best Answer

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

Avatar
Opusti
Avtor

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

Related Posts Odgovori Prikazi Aktivnost
3
sep. 21
9388
1
feb. 21
4908
4
jan. 20
3195
0
nov. 18
4431
0
apr. 17
3652