تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6082 أدوات العرض

I'm trying to add a relational field to a model entity ( Odoo 11 ). I have two classes

 

# -*- coding: utf-8 -*-

from odoo import models, fields, api

class Cantiere(models.Model):

_name = 'modulotest01.cantiere

name = fields.Char(required=True)

description = fields.Text()

direttore = fields.Many2one('modulotest01.direttore', string='Direttore',index=True,ondelete='cascade'

class Direttore(models.Model):

_name = 'modulotest01.direttore'

name = fields.Char(required=True)

start_date = fields.Date(

#cantiere_id = fields.One2Many('modulotest01.cantiere', 'direttore_id'


Obviously this code doesn't work and i don't know why

الصورة الرمزية
إهمال
أفضل إجابة

Hai Alessandro Losco

in the first class Cantiere, you define a "Many2one" field. and the second class direttore, you define a One2many (You use a wrong key word #One2Many). In this One2many you need use the field direttore(Many2one). But you use "direttore_id"
cantiere_id = fields.One2many('modulotest01.cantiere', 'direttore')

Try to correct these issues, and make the relation.
If you have any doubt free to contact.
Thank you,

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 23
2219
0
ديسمبر 22
2862
0
يونيو 21
2869
0
يونيو 20
5338
1
نوفمبر 19
2698