我有这样的模型:
class MyDict(models.Model):
_name='my_module.my_dict'
field1=fields.Char()
field2=fields.Char()
field3=fields.Char()
数据看起来像:
obj_1 | attr_1 | val_1
obj_1 | attr_2 | val_1
obj_1 | attr_2 | val_2
obj_2 | attr_1 | val_1
obj_2 | attr_1 | val_2
从另一个模型我想逐步使用这个数据
class NewModel(models.Model):
_name='my_module.new_model'
selection1=field.Selection(selection='_get_selection1')
selection2=field.Selection(selection='_get_selection2')
selection3=field.Selection(selection='_get_selection3')
def _get_selection1(self):
my_list = []
selection_list = []
full_list = self.env['my_module.my_dict'].search([])
for record in full_list:
if record.field1 not in my_list:
my_list.append(record.field1)
for list_item in my_list:
selection_list.append((str(list_item), str(list_item)))
return selection_list
第二个选择需要取决于第一个
@api.onchange('selection1')
def _get_selection2(self):
my_list = []
selection_list = []
full_list = self.env['my_module.my_dict'].search([('field1', '=', self.selection1])
for record in full_list:
if record.field2 not in my_list:
my_list.append(record.field2)
for list_item in my_list:
selection_list.append((str(list_item), str(list_item)))
return selection_list
但我在这里发现了错误
File "/opt/odoo13/odoo/odoo/models.py", line 5817, in process
if res.get('value'):
AttributeError: 'list' object has no attribute 'get'
我怎样才能得到 selection_list 取决于第一个选择