跳至内容
菜单
此问题已终结
1 回复
6764 查看

I code part as below :

class Selection(models.Model):
    _name = 'selection.model' 
    _rec_name = 'select'
    select = fields.Char(string='selections', required=True)

class Checks(models.Model):
    _name = 'buy.goods' 
    strs = fields.Char()
    results = fields.Many2one('selection.model', string='Selections')

    @api.onchange('strs')
    def _get_results(self): 
        goods = self.strs.split(',')
        ...

I want to show all items of 'goods' as selections of 'results' field; and when 'strs' field is changed, the selections of 'results' field should be updated at once. so how shall I code for this?


形象
丢弃
最佳答案

Hi,  

if you want to display the many2one field like selection  you can use  widget="selection" and you can  write a method on onchange of many2one field and return domain in that method based on condition.

@api.onchange('result')
def onchange_result_ids(self):
if self.strs:
domain = {'result': [(condition)]}
return {'domain': domain}

形象
丢弃
编写者

thanks for your reply;

but i think the effect of your code is select some items but what i means is that the select items of 'result' are from 'strs'; for example, 'strs' = 'this is good'; then the select items list of 'result' should be ['this','is','good']

相关帖文 回复 查看 活动
1
8月 23
1915
1
3月 21
4122
0
10月 20
3241
0
12月 18
13
1
8月 17
3693