Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
8486 Vizualizări

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


Imagine profil
Abandonează
Cel mai bun răspuns

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'

Imagine profil
Abandonează
Autor

ProgrammingError: column rel_country_table2.country_model_id2 does not exist

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

Autor

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.

Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

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

Autor

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 Răspunsuri Vizualizări Activitate
1
iun. 16
3248
1
mai 17
5193
1
mar. 16
22232
5
mar. 16
10195
3
mai 24
15107