跳至內容
選單
此問題已被標幟
1 回覆
9887 瀏覽次數

I need to create a One2Many field in Odoo, but using the same model where the field is created. For example.

class WindowForm(models.Model):

        _name= 'window.form'

        doors = fields.One2Many('window.form')

As you can see the One2Many field has the same model of the class where it is declared.

I know that the above declaration is not correct, but that is exactly my doubt. When you define a One2Many field you have to create Many2One field in the other model. So, how can i declare the One2Many?

Thanks in advanced.

頭像
捨棄
最佳答案

Hi,

class WindowForm(models.Model):

    _name = 'window.form' 


    parent_id = fields.Many2one('window.form', string="Parent")

    child_ids = fields.One2many('window.form', 'parent_id', string="Lines")


Bye

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
6月 18
3840
1
2月 16
4289
0
2月 16
4189
1
3月 23
2216
0
12月 22
2858