Skip to Content
Menu
This question has been flagged
1 Reply
1606 Views

_inherit = ['survey.page','survey.question']

I know this is the right way but i am unable to do it as it requires _name but i dont have any new name as i want to inherit into one of them, how can this be dealt? Thanks in advance

Avatar
Discard
Best Answer

Hello Abdullah,

You may give one of them into _name in which you want to inherit other model.

Let's you wanna inherit model 'survey.question' in model 'survey.page' then you may write this like below.

_name = 'survey.page'
_inherit = ['survey.page', 'survey.question']
I hope this will help your query. Feel free to ask in case of any query.


Thanks,

Aman Prakash,

Webkul Software Private Limited

Avatar
Discard
Author

Thanks for replying sir but this is giving me following error

RecursionError: maximum recursion depth exceeded in comparison...

Complate code is as follow

class MYModel(models.Model):

_name = 'survey.page'

_inherit = ['survey.page','survey.question']

survey_score = fields.Integer(string='Total Score',compute='_compute_total_score')

@api.depends('total_marks')

@api.one

def _compute_total_score(self):

records = self.env["survey.question"].search([('page_id', '=', self.id)])

self.survey_score = sum(records.mapped('total_marks'))

I think you have helped me before regarding this code. I am very thankful to you

Hello Abdullah,

I gave you the way to inherit two models in one model.

You got this error due to your calculation which is going one model to another model again and again.

Modify your method to calculate total marks. This is raising the RecursionError.

Be careful with inheriting two models when they have related fields to each other.

Please try to make it simple.

I hope this will resolve your query.

Thanks,

Aman Prakash,

Webkul Software Private Limited