Customizing the Many2Many Widget in Odoo

Hello Odooers & Developers!

Welcome to another insightful Odoo technical article! In this post, we're diving into one of the most commonly used and flexible field types in Odoo: the Many2many widget.

Whether building a new module or customizing one, understanding how to use the Many2many field and its different widget options will help you create better user experiences and more efficient data relationships.

What You Will Learn in This Guide

  • What is a Many2many Field in Odoo
  • Types of Widgets for Many2many Fields
  • How to Use many2many_tags
  • How to Use many2many_checkboxes
  • How to Use many2many_tags_avatar
  • How to Use many2many_binary

What is a Many2many Field?


A Many2many field is used to create a bidirectional relationship between two models; each record in one model can be associated with multiple records in another, and vice versa.

For example, let's say you have a mall. Shop model, and you want to assign multiple res. Partner customers to it. This is where the Many2many relationship comes in.

Step-by-Step Implementation

1. Define the Many2many Field in Your Model (.py)

First, we define the field in Python. This field establishes the relationship.

Syntax : 

.py

from odoo import models, fields

class Mall(models.Model):

    _name = 'mall.shop'
    _description = 'Shop'
    customer_ids = fields.Many2many('res.partner', string='Customers')


Explanation : 

.py

customer_ids = fields.Many2many('res.partner', string='Customers')

     This line creates a Many2many field named customer_ids:

  • 'res.partner' is the model you're linking to — in this case, it means each shop can be linked to multiple customers.
  • string='Customers' defines the label that will appear in the UI.

So in simple words, this field allows you to select multiple customers for one shop, and each customer can also be linked to multiple shops if needed.

2. Define the Many2many Field in XML File (.xml)

  • Below is the form view of mall.shop object and we define customer_ids field into the Form view.

XML

<record id="view_shop_form" model="ir.ui.view">
    <field name="name">view.shop.form</field>
    <field name="model">mall.shop</field>
    <field name="arch" type="xml">
        <form string="Shop">
            <group>
                <field name="customer_ids" />
            </group>
        </form>
    </field>
</record>

   Before using widget in m2m field , below is the example image of how it is look:


3. Using Many2many Widgets in XML Views

Odoo provides multiple widgets to render Many fields in different ways.

a. Default Tags View – many2many_tags

This is the most commonly used widget. It displays selected records as tags and lets users easily add/remove records.

Use When:

  • You want a clean and compact UI
  • Users need to add or remove items quickly
  • You're working with relational data like categories, users, tags, etc.

Example XML Code:

XML

<field name="customer_ids" widget="many2many_tags"/>

 

Below is an example image showing how the Many2many field looks with this widget:

b. Checkbox View – many2many_checkboxes

This widget shows each related record with a checkbox, letting users select or unselect easily.

Use When:

  • You want to show all available choices clearly
  • Valid for permissions, categories, or feature selections

Example XML Code:

XML

 <field name="customer_ids" widget="many2many_checkboxes"/>

Below is an example image showing how the Many2many field looks with this widget: 


c. Avatar View – many2many_tags_avatar

If your related model has image fields, this widget shows avatars alongside the name tags.

Use When:

  • You're dealing with models that include images, like users or customers.
  • You want to make the interface more visual and engaging.

Example XML Code:

XML

<field name="customer_ids" widget="many2many_tags_avatar"/>

Below is an example image showing how the Many2many field looks with this widget:


d. many2many_binary – Binary File Uploads

 -  This widget is often used to upload multiple binary files (like images or PDFs) to a record.

 -  To use this widget, your Many2many field should be related to the ir.attachment model, which is the standard Odoo model used for storing files and attachments.

attachments = fields.Many2many('ir.attachment', string="Files")

Use When:

  • Users need to upload several documents
  • Useful for attaching contracts, IDs, photos, etc.

Example XML Code:

XML

<field name="attachments" widget="many2many_binary"/>

 Below is an example image showing how the Many2many field looks with this widget:


Conclusion

Many fields are core to building rich and dynamic data models in Odoo. They allow you to create flexible, bidirectional relationships between different models, whether you're linking products to categories, students to courses, or customers to shops.

However, how you display those relationships can make a massive difference in the user experience. That’s where many widgets come in.

Each widget, whether it's tags, checkboxes, avatars, or file uploads, serves a unique purpose. Choosing the right widget based on your business logic and user interface needs can make your forms more interactive, clear, and efficient.

So next time you're working with a Many2many field, consider which widget fits best and deliver a smarter, smoother, and more enjoyable experience to your users.

If you want odoo technical training on any odoo version , please let us know by mail at odoo@devintellecs.com. Then next, our odoo expoert will conduct online or offline training with you 


Devintellecs & team are odoo training providers in the USA and INDIA, so we will try our best to give the training either individal or any bulk employee company.


if you want to check your odoo technical or functional knowledge, then we have prepared the odoo EXam practice test for the odoo technical & functional people.


Odoo DEV April 24, 2025
Share this post
Archive
Sign in to leave a comment
How to use float_time widget in odoo