Skip to Content
मेन्यू
This question has been flagged
1 Reply
2218 Views

I have two objects, related by a Many2one relationship. articles can have many article_image records associated with them.

Everything is in place to create article_images and I can link them back to articles in the article_image form. This works great. (Many2one)

But when I'm looking at the article's form, I want to see the linked article_images. (One2many)

I can't seem to get this to work, and keep getting transient module states were reset errors.

Here is my code:

from odoo import fields, models

class MKBArticleImage(models.Model):
_name = "mkb.article_image"
_description = "Knowlege Base Article Images"
article_image_description = fields.Char(string='Description',required=True)
article_image_image = fields.Image(string='Image',required=True)
related_article = fields.Many2one(string="Article",required=True,comodel_name='mkb.article')
 
 
class MKBArticle(models.Model):
_name = "mkb.article"
_description = "Knowlege Base Article"
article_number = fields.Char(string='Article #',required=True)
article_description = fields.Char(string='Description',required=True)
article_details = fields.Text(string='Details',required=True)
article_type = fields.Selection(
string='Type',
selection=[('problem_solution', 'Problem/Solution'), ('how_to', 'How-to'), ('hint_or_tip', 'Hint/Tip'), ('reference', 'Reference'), ('process_procedure', 'Process Procedure')],
help="Used to separate Articles.")
related_article = fields.One2many(string="Image Links",comodel_name='mkb.article_image')

(*** the last line causes the error ***)

Avatar
Discard
Author Best Answer

Solved:

in class MKBArticle(models.Model) the last line should be:

article_images = fields.One2many(string='Images',comodel_name='mkb.article_image',inverse_name='related_article')

I had forgotten to put in the inverse_name attribute.

Avatar
Discard
Related Posts Replies Views Activity
0
दिस॰ 22
2860
0
जून 21
2866
0
जून 20
5338
1
नव॰ 19
2696
0
दिस॰ 18
93