wasd
wasd

Reputation: 1572

How to render in form view model's Many2one's field field in Odoo?

Let's say I have

class A(models.Model):    
    _name = "A"
    field_a = fields.Many2one('B')


class B(models.Model):
    _name = "B"
    field_b = fields.Char()

On a form which model is A I need to render field_b. I tried like this:

<field name="field_a.field_b" /> 

but with no luck

What is the correct way to do this?

Upvotes: 0

Views: 452

Answers (1)

Charif DZ
Charif DZ

Reputation: 14721

in order to display field from m2o in the current view create a related field.

class A(models.Model):    
    _name = "A"
    field_a = fields.Many2one('B')
    field_b = fields.Char(related='field_a.field_b')


class B(models.Model):
    _name = "B"
    field_b = fields.Char()

And now in model A view you can just:

 <field name="field_b" /> 

Upvotes: 2

Related Questions