Skip to Content
Menu
This question has been flagged
4 Replies
7240 Views

Hello,

I have 2 fields like this:


'field1': fields.many2many('res.country'),
'field2': fields.many2many('res.country'),


Now when I put data in the first field and I save that, it puts automatic the same value in the second field. Why is that so?

How Can I fix this issue?


I want that the user can handle the two fields seperate. 

Thank You


Avatar
Discard
Best Answer

You need to define relation tables or its ids, because many2many field creates one new table in your database. That joints the model together. So,

try like this,

'field1': fields.many2many('res.country','rel_country_table1','current_model_id1','country_model_id1'),
'field2': fields.many2many('res.country','rel_country_table2','current_model_id2','country_model_id2'),

In this example this will create two new tables in your database.

that is rel_country_table1 and rel_country_table2 with two columns 'current_model_id','country_model_id'

Avatar
Discard
Author

ProgrammingError: column rel_country_table2.country_model_id2 does not exist

LINE 1: SELECT rel_country_table2.country_model_id2, rel_country_tab...

Author

It's not working, I really don't know how I can fix that.

You just need to remove your old database and try with new one.

Best Answer

Hello

you can use second syntax of Many2many field

1> field_ids = fields.Many2many('<<model.name>>')

2> field1_ids = fields.Many2many('<<model.Name>>','table_name', 'column1','other_col_name') 

Avatar
Discard
Author

And what we put in those relation, column1 and column2?

Author

this is not working with your solution!!!

field1_ids = fields.Many2many('<<model.Name>>','table_name', 'column1','other_col_name')

try this

in relation field you can specify the new table name

in column1 and column2 field you can specify the name of colums

after that you can show this table in database with named as you pass name in second parameter with two colums that specified in third and fourth parameter

Related Posts Replies Views Activity
1
Jun 16
2335
1
May 17
4466
1
Mar 16
20509
5
Mar 16
8811
3
May 24
13841