I have a table A
Table A:
---------------------------------------
id | valueName | value
---------------------------------------
1 | 2001 | Nepal
---------------------------------------
2 | 2002 | Thailand
---------------------------------------
My model definition looks like this:
chosing_opt = ("2001", [
("Sig1", T("Sig1"), "I", "E", "O"),
("Sig2", T("Sig2"), "E", "S", "O"),
("Sig3", T("Sig3"), "E", "M", "O")
],
"2002", [
("Val1", T("Val1"), "I", "E", "O"),
("Val2", T("Val2"), "E", "S", "O"),
("Val3", T("Val3"), "E", "M", "O")
],
)
define_table(tablename,
Field("priority",),
Field("code", "list:string",),
)
What I want is when user fill in the code
Field, say 2001
. Since 2001 is in Table A, it should give me a drop-down in priority
field showing Sig1, Sig2 and Sig3 of chosing_opt
, and if 2002
in code
, then a drop-down in priority
field showing Val1, Val2 and Val3 of chosing_opt
.
Please suggest. Thanks
The structure is a bit different in your code so you have to work to convert it into something that is easy to ready code-wise (although this is not the only way - you could use for/while loops).
The idea is to convert the values like
2001
and2002
into keys and the next tuples into their respective values.Finally, test it as follows:
Your results will look like this:
Note: Not sure what
T
is in your code, so I pre-empted it by converting it to string (by using this as the first lineT = str
) for my own testing so the results show accordingly