跳至內容
選單
此問題已被標幟
2 回覆
10004 瀏覽次數

Do you know how to check whether the field exists (is defined in model) in the report template?

For example if field xxx is defined FOO is printed:

<t t-if="test(o.xxx)">FOO</t>

頭像
捨棄
作者 最佳答案

I found the answer:

<t t-if="'xxx' in o">FOO</t> 

Update, or:

<t t-if='o.get("xxx")'>FOO</t> 



頭像
捨棄
最佳答案

You can write, also this,

<t t-if="o.xxx">

FOO

</t>

頭像
捨棄
作者

This is not a good solution, if filed xxx not exists in model cause the error: ... object has no attribute 'xxx'" while evaluating.

You are right, I misunderstood the question.. I forgot to notice "field exists (is defined in model)".

相關帖文 回覆 瀏覽次數 活動
0
3月 24
3344
3
10月 16
6981
1
12月 23
26978
1
3月 15
7905
3
9月 24
46974