Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
3942 Widoki

I have a new model:

# -*- coding: utf-8 -*-
from openerp.osv import osv, fields
class test_branch(osv.osv):
 _name = "test.branch"
 _columns = { 'id': fields.char(string='ID'), 'name': fields.char(string='Name') }


Now when I make on another model an many2many relation to this:


class test_branch_rel(osv.osv):

_name = 'test.branch.rel'

_columns = { 'branch_left_id': fields.many2one('test.branch'),

'branch_right_id': fields.many2one('test.branch', 'Relationed Branch'), }


'test_branch': fields.many2many('test.branch', 'test_branch_rel', 'branch_left_id', 'branch_right_id'),
'test_zielbranch': fields.many2many('test.branch', 'test_branch_rel', 'branch_right_id', 'branch_left_id')


I can't save that many2many field:

I get this error:

integrity errors

[a reference object: test.branch - test.branch]


Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

the correct syntax is
'test_branch': fields.many2many('test.branch', 'test_branch_rel', 'branch_left_id', 'branch_right_id'),


but you didnt defined 'branch_left_id'. you have to make these also as a many2one field.


Awatar
Odrzuć
Autor

where I need to define branch_left_id ?

In this model _name = 'test.branch.rel'

Najlepsza odpowiedź

Hi,

The syntax for Many2Many fields is :-

    fields.Many2many(comodel_name=None, relation=None, column1=None, column2=None, string=None)

Here comodel_name is the name of target model,

and relation is name of table that store relation in database. ie it will create a table in database with the given name, which store the relation,

column1 and column2  are the name of colums of relation-table in database.


Hope this helps.


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
maj 16
5474
1
mar 15
5717
0
gru 22
2841
4
cze 22
20856
2
wrz 17
10092