Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2289 มุมมอง

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 23
2046
2
ส.ค. 23
4301
4
ส.ค. 23
20617
3
ต.ค. 22
11083
3
มี.ค. 22
37402