Skip to main content

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

This module adds a new Many2many custom field with a create_table attribute.

Table of contents

Usage

Many2manyCustom field is useful when a direct access to the relational table is needed, for example to be editable in a dedicated tree view.

Let’s consider following models:

class MyModelA(models.Model):

    _name = 'my.model.a'

    my_model_b_ids = fields.Many2manyCustom(
        'my.model.b',
        'my_model_a_b_rel',
        'my_model_a_id',
        'my_model_b_id',
        create_table=False,
    )


class MyModelB(models.Model):

    _name = 'my.model.b'

    my_model_a_ids = fields.Many2manyCustom(
        'my.model.a',
        'my_model_a_b_rel',
        'my_model_b_id',
        'my_model_a_id',
        create_table=False,
    )


class MyModelABRel(models.Model):

    _name = 'my.model.a.b.rel'

    my_model_a_id = fields.Many2one(
        'my.model.a',
        required=True,
        index=True,  # Index is mandatory here
    )
    my_model_b_id = fields.Many2one(
        'my.model.b',
        required=True,
        index=True,  # Index is mandatory here
    )

By setting create_table=False on the Many2manyCustom field, and using the relational table name, as _name for the relational model, we’re able to define a dedicated tree view for my.model.a.b.rel.

<record id="my_model_a_b_rel_list_view" model="ir.ui.view">
    <field name="name">my.model.a.b.rel.list.view</field>
    <field name="model">my.model.a.b.rel</field>
    <field name="arch" type="xml">
        <list editable="top">
            <field name="my_model_a_id" />
            <field name="my_model_b_id" />
        </list>
    </field>
</record>

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Camptocamp

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

This module is part of the OCA/server-tools project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Metadata

Release files for odoo-addon-base-m2m-custom-field 18.0.1.0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for odoo-addon-base-m2m-custom-field 18.0.1.0.0.3
File Interpreter ABI Platform
odoo_addon_base_m2m_custom_field-18.0.1.0.0.3-py3-none-any.whl Python 3 none any Details

Release files / odoo_addon_base_m2m_custom_field-18.0.1.0.0.3-py3-none-any.whl

Download URL odoo_addon_base_m2m_custom_field-18.0.1.0.0.3-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8545ed36c6ea8d2c728d1d8afccf5f82dccdb23d32b04c620d63020748a5e707
BLAKE2b-256 checksum
How to use checksums
d4f6e10011cc9768ef1c388b1165c56f0af2278912f228e2d7f2bdea813bc558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page