Odoo Help


How to display a field in a view from a different model?

Luigi Sison
on 20/01/15 18:26 5.981 views

Use Case:

Model 1 contains 2 fields: ID and Name

Model 1 has a one to many relationship with Model 2.

View A displays the contents of Model 2.

How can View A also display Name from Model 1?

model 1 and model 2 from same module?

Demirel yakito
on 20/01/15 23:48


On Tuesday, January 20, 2015, David <krevatharamanan@gmail.com> wrote:

model 1 and model 2 from same module?

Sent by Odoo S.A. using Odoo about Forum Post How to display a field in a view from a different model?


Best regards,

Luigi Sison | Implementation Partner
phone +1 612 281 2551
824 Phoenix Lane | Foster City, CA 94404 | USA
lsison@moxylus.com | Our Website | My LinkedIn Profile

Moxylus, Luigi Sison
on 21/01/15 01:44

Axel, Thank you for the code. I need to implement this in Odoo SaaS. How do you specify 'name_rel': fields.related('model1_id', 'name', type='char', string='Model 1 Name' in Settings>Technical>Database Structure>Models ?

Moxylus, Luigi Sison
on 21/01/15 12:29

Anil R. Kesariya (Jupical Technologies)

--Anil R. Kesariya (Jupical Technologies)--
| 7 6 8
Rajkot, Índia
--Anil R. Kesariya (Jupical Technologies)--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Anil R. Kesariya (Jupical Technologies)
On 20/01/15 23:59

Hello Luigi Sison,

If it is normal xml view for form and tree than just put name of your field (many2one) of that model, if you have defined name field on that model than name value will be display. you cannot display other fields. If you want to display multiple field display for many2one than you need to override name_get() of that model.

and yes, if it is about q-Web report than you can follow the answer given by Jeff Beidler .

Hope this will help.






Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 21/01/15 00:00

In every one2many relationship field there is a many2one field in the other side of the relation, so you should have in Model 2 a many2one field to Model 1. To display the name of Model 1 in a form view of Model 2 you need to declare the name as a related field in Model 2 class definition, something like this:

class model1(osv.osv):
    _name = 'model1'
    _columns = {
        'name': fields.char('Name', size=64, required=True),
        'model2_ids': fields.one2many('model2', 'model1_id', string='Models 2'),

class model2(osv.osv):
    _name = 'model2'
    _columns = {
        'name': fields.char('Name', size=64, required=True),
        'model1_id': fields.many2one('model1', string='Model 1'),
        'name_rel': fields.related('model1_id', 'name', type='char', string='Model 1 Name')

Then in your view of Model 2 just add 

<field name="name_rel"/>

law rence
On 15/10/17 22:35

try to use this

from odoo import models, fields, api

class MyModel(models.Model):
    _name = "my.model"

    another_model_ids = fields.One2Many(
        comodel_name="another.model", inverse="my_model_id",
        string="Another Model Entries")

class AnotherModel(models.Model):
    _name = "another.model"

    my_model_id = fields.Many2One(
        comodel_name="my.model", string="My Model")
    number = fields.Integer(string="A Number")
    yet_another_model_id = fields.Many2One(
        comodel_name="yet.another.model", string="Yet Another Model")

    def name_get(self):
        # with context flags you can implement multiple
        # possibilities of name generation
        # best example: res.partner
        res = []
        for another_model in self:
            res.append((another_model.id, "{} {}".format(
        return res

class YetAnotherModel(models.Model):
    _name = "yet.another.model"

    name = fields.Char(string="Name")
Jeff Beidler
On 20/01/15 18:40

Try something like <span t-field="o.mod1_id.name">, where "mod1_id" is the name of your relation field to Model 1.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 20/01/15 18:26
Seen: 5981 times
Last updated: 15/10/17 22:35