Search code examples
odoo-viewodoo-12

How to populate a dropdown list with a custom field in odoo12?


Generally when a many2one field is declared and a model is referred to in that many2one field, this drop down list populates the entries from the field named name but i want to populate the drop down list with a custom field say companyName. How can i achieve this? An example would be really helpful

Thanks


Solution

  • I got to know that we can achieve this using

    Method 1 works only if there is no field named "name" and if there is already a field named "name" then try method 2

    1. Using the _rec_name = '[field-name]'. for eg. _rec_name = 'companyName'
    2. By overriding the name_get() method in the source model i.e., in the model from which you want the fields to populate the list with.