Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
9288 มุมมอง

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
Many2one related field แก้ไขแล้ว
3
ก.ย. 21
9401
Many2one field: 'id' instead of 'name' แก้ไขแล้ว
1
ก.พ. 21
4909
Representation of Many2one in view แก้ไขแล้ว
4
ม.ค. 20
3212
0
พ.ย. 18
4451
0
เม.ย. 17
3669