Skip to Content
Menú
This question has been flagged
1 Respondre
1933 Vistes

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
Descartar
Autor 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
Descartar
Related Posts Respostes Vistes Activitat
0
de des. 22
2609
0
de juny 21
2627
0
de juny 20
5107
1
de nov. 19
2499
0
de des. 18
93