跳至內容
選單
此問題已被標幟
2 回覆
6262 瀏覽次數

Hello,

I have simple database which has 3 models as follows

1- camps (to store Camps master data)

2- players (to store players master data)

3- players_camps (to store camps each player has attended)

the code for all models as follows:

class Camps(Model):
     _name = 'camps'
     name = Char('Name')
organizer = Char() 
date_from = Date('From date')
     date_to = Date('To date')     
     place = Char()
     supervisor = Char()
     notes = Text()

class players(Model):
     _name = 'player'
     name = Char()
     camps = One2many('player_camps', 'player')

class player_camps(Model):
     _name = 'player_camps'
     camp = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
organizer = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
   place = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
     date_from = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
date_to = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
     result = Integer(default=0)
when I display players camps (using One2many widget in the view ) I can see only the camp name but the other data
like organizer or place (which are stored in master model of camps) not shown
how can I show this data in the tree view of the players camps view ?
頭像
捨棄
作者 最佳答案

Sorry I can't comment (have to have 8 points while I have only 7) so I added as an answer

when I add your code I get this result

https://s32.postimg.org/myykvf4qt/Screenshot_from_2016_07_16_12_51_15.png


頭像
捨棄
最佳答案

Hello Mohamed,

For Display all fields of one2many model you can set one2many field by this way that is describe below into form view of player model.

Example: 

<field name="camps">
     <tree>
         <field name="camp"/>
         <field name="organizer"/>
         <field name="place"/>
         <field name="date_from"/>
         <field name="date_to"/>
     </tree>
</field>

I think you was forgot to write may2one of player model in player_camps mode. because you have add one2many field in player name camps for this field relate with player model with its player field. i think here i was missing.


Hope this helps.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
10月 21
1691
2
2月 25
5970
1
12月 24
1494
1
11月 22
16067
1
11月 22
5834