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

 I'm trying to overide write.

I want to read the one2many field  in write method. Unlike create method which return a object that i can access to get data. write method just give me a true/false.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Approach 1:

def write(self, vals):

    record =  super(YourClass, self).write(vals) // you can access to the object like this

    ... do whatever you wish to record object like record.you_field

    return record

Approach 2:

def write(self, vals):

    your_m2o_field = vals.get('your_m2o_field', None) // this approach is feasible only if your_m2o_field has edited.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Duy Anh,
Yes you can read it from the vals from the write orm method. 
Vals is the dictionary which contains the updated values in it. Yes you can use the for loop on self and work as you want after the write super call.

Hope it will help you.



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 20
12608
1
พ.ย. 22
1926
1
ต.ค. 22
2467
0
ม.ค. 22
2573
1
มิ.ย. 25
1592