Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
4 Відповіді
8487 Переглядів

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


Аватар
Відмінити
Найкраща відповідь

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'

Аватар
Відмінити
Автор

ProgrammingError: column rel_country_table2.country_model_id2 does not exist

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

Автор

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.

Найкраща відповідь

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') 

Аватар
Відмінити
Автор

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

Автор

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 Відповіді Переглядів Дія
1
черв. 16
3252
1
трав. 17
5193
1
бер. 16
22232
5
бер. 16
10195
3
трав. 24
15108