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

class Teachers(models.Model):

_name = 'academy.teachers'

name = fields.Char()

course_ids = fields.One2many('product.template','teacher_id', string="Courses")


class Courses(models.Model):

_name = 'academy.courses'

_inherit = 'product.template'

name = fields.Char()

teacher_id=fields.Many2one('academy.teachers', string="Teacher")



الصورة الرمزية
إهمال

These tips will help you: https://goo.gl/8HgnCF

أفضل إجابة

@Shivam Mahajan
Your error is because in your Courses class you are creating a new model 'academy.courses' using the model 'product.template' as a prototype. You are not extending the model 'product.template' with the field teacher_id and in your class Teachers you have the field course_ids as a one2many relation with the model 'product.template', that require a field named 'teacher_id' as a many2one to 'academy.teachers' in 'product.template'. 
To fix it you have two options, depending of what you need to do

1- You can change this:

course_ids = fields.One2many('product.template','teacher_id', string="Courses")

to this:

course_ids = fields.One2many('academy.courses','teacher_id', string="Courses")

 
2- Or you can change this:

class Courses(models.Model):

_name = 'academy.courses'

_inherit = 'product.template'

To this:

class Courses(models.Model):

_inherit = 'product.template'

Only use one of the two options. The #1 will keep the prototype inheritance from the model 'product.template' but fix the relation and the #2 will extends the model 'product.template' with the field teacher_id

Your choice

الصورة الرمزية
إهمال
الكاتب

@Axel ..Thanks a lot for the help......It really works

Happy to help you, thanks me with an upvote and accept the answer

أفضل إجابة

Hi Shivam,

This type of error occurs if you did not add correct dependency in your module. 

Please check depends in __openerp__.py file in your module. Here in this case add 'product' because you are inheriting product.template

 

'depends': ['base','product',],


Hope this helps.


 

الصورة الرمزية
إهمال
الكاتب

Hi Baiju , Thanks a lot for the response .But I am satisfied by the answer of Axel

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
أغسطس 25
519
0
نوفمبر 23
2055
KeyError: 'socket' تم الحل
2
أبريل 25
8697
4
أبريل 19
5301
1
مارس 15
18767