Se rendre au contenu
Menu
Cette question a été signalée
4 Réponses
8473 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur

ProgrammingError: column rel_country_table2.country_model_id2 does not exist

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

Auteur

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.

Meilleure réponse

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
Ignorer
Auteur

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

Auteur

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

Publications associées Réponses Vues Activité
1
juin 16
3235
1
mai 17
5168
1
mars 16
22228
5
mars 16
10172
3
mai 24
15096