Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to use many2one field in a function

on 6/29/16, 10:40 AM 361 views

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?

Nikunj Antala
On 6/30/16, 1:16 AM

 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=???

on 6/30/16, 2:31 AM

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

Nikunj Antala
on 6/30/16, 2:53 AM


| 4 3 5
Hyderabad, India

On 6/30/16, 1:20 AM


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

on 6/30/16, 2:32 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 6/29/16, 10:40 AM
Seen: 361 times
Last updated: 6/30/16, 2:52 AM