Note that there are some explanatory texts on larger screens.

plurals
  1. POhow many2many defined for custom module
    text
    copied!<p>I tried to use many2many relational field in my custom module "notebook". Code is given below:</p> <p>notebook.py:</p> <pre><code>from osv import fields, osv import time class notebook(osv.osv): _name = "notebook" _description = "Simple Notebook" _columns = { 'title' : fields.char('Title', size=30, required=True), 'tag_ids': fields.many2many( 'hello', 'title', 'name', string="Tags" ), } notebook() class hello(osv.osv): _name = 'hello' _columns = { 'name':fields.char('Name',size=30), 'note_ids': fields.many2many( 'notebook', 'name', 'title', string="Notebooks" ), } hello() </code></pre> <p>notebook_view.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;openerp&gt; &lt;data&gt; &lt;record model="ir.ui.view" id="notebook_form_view"&gt; &lt;field name="name"&gt;notebook.form&lt;/field&gt; &lt;field name="model"&gt;notebook&lt;/field&gt; &lt;field name="type"&gt;form&lt;/field&gt; &lt;field name="arch" type="xml"&gt; &lt;form string="Notebook"&gt; &lt;field name="title" /&gt; &lt;field name="tag_ids" widget="many2many_tags"/&gt; &lt;/form&gt; &lt;/field&gt; &lt;/record&gt; &lt;record model="ir.actions.act_window" id="action_notebook_form"&gt; &lt;field name="name"&gt;notebook&lt;/field&gt; &lt;field name="res_model"&gt;notebook&lt;/field&gt; &lt;/record&gt; &lt;menuitem name="NotebookParent" icon="terp-project" id="NotebookParent_menu" /&gt; &lt;menuitem name="NotesChild" parent="NotebookParent_menu" id="NotesChild_menu" /&gt; &lt;menuitem name="Header" parent="NotesChild_menu" id="Header_menu_mainform" action="action_notebook_form" /&gt; &lt;/data&gt; &lt;/openerp&gt; </code></pre> <p>hello_view.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;openerp&gt; &lt;data&gt; &lt;record model="ir.ui.view" id="hello_form_view"&gt; &lt;field name="name"&gt;hello.form&lt;/field&gt; &lt;field name="model"&gt;hello&lt;/field&gt; &lt;field name="type"&gt;form&lt;/field&gt; &lt;field name="arch" type="xml"&gt; &lt;form string="Hello Form"&gt; &lt;field name="name" select="1" /&gt; &lt;field name="note_ids" widget="many2many_list"/&gt; &lt;/form&gt; &lt;/field&gt; &lt;/record&gt; &lt;/data&gt; &lt;/openerp&gt; </code></pre> <p>There is no error in installing and the fields are also displayed and data is stored in the Database.</p> <p>My problem arises as inter-relationship between note_ids and tag_ids is not proper.</p> <p>Example:</p> <pre><code>If I have a notebook record as : title = sample tags = tag1, tag2 The tags are created in hello record as: tag1 record: name="tag1" Notebooks = "" tag2 record: name="tag2" Notebooks= "" </code></pre> <p>Why is the relationship not maintained?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload