如何定义动态选择字段,用户可以在其中添加未预定义的新项目 此代码定义静态选择字段:
的分数:field.selection([(' KEY1''值1').....],字符串='得分&#39),
答案 0 :(得分:0)
试试这个链接How to add a filter to selection field in odoo,我已经发布了我的回答:
@api.model
def _get_room_type_list(self):
# [('meeting','Meeting Room'),('discussion','Discussion Room'),('auditorium','Auditorium'),('board','Board Room')]
vals=[]
for record in self.env['hotel.management'].search([]):
if record.roomuser in ['stpi','Incubation'] :
vals.extend([('meeting','Meeting Room'),('discussion','Discussion Room')])
if record.roomuser in ['both'] :
vals.extend([('auditorium','Auditorium'),('board','Board Room')])
return vals
roomType=fields.Selection(string="Room Type", selection=_get_room_type_list, default='meeting', required=True)
答案 1 :(得分:0)
您最好的选择是创建一个多字段字段:
class yourmodule_score_rel(models.Model):
_name = 'yourmodel.score.rel'
name = fields.Char('Score')
在你的模块课上:
score_id = fields.Many2one('yourmodel.roles.rel', string='Score')