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

I have an on_change method that assigns a list of tuples to a Selection field


But I get the error message in the subject

Why is that ?

The tuples are like (int, string)


I tried casting the 2 elements in the tuples to 2 strings, int for the id and string for the value, string for the id and int for the value...


I just want to create a list of choices for a dropdown menu field that depends on the value in another field


How am I supposed to do that ?

形象
丢弃
最佳答案

Hi Adriano,

Try this code 

@api.onchange('selection_field')
def _onchange_domain(self):
if self.selection_field == 'value':
domain = [('id', '=', self.id)]
else:
domain = []
return {'domain': {'another_field': domain}}

Also, Check this reference to apply dynamic domain for relational fields 

Dynamic domain


Regards

形象
丢弃
编写者 最佳答案

Thank you !!

This works !

BUT !!


It's deprecated

i read here an answer about how to properly do this but I don't understand

形象
丢弃

You can use dynamic domain methods

相关帖文 回复 查看 活动
1
10月 23
1528
2
8月 23
3630
4
8月 23
19948
3
10月 22
10460
3
3月 22
36843