Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
10032 Näkymät

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>

Avatar
Hylkää
Tekijä Paras vastaus

I found the answer:

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

Update, or:

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



Avatar
Hylkää
Paras vastaus

You can write, also this,

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

FOO

</t>

Avatar
Hylkää
Tekijä

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)".

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
maalisk. 24
3356
3
lokak. 16
6993
1
jouluk. 23
26988
1
maalisk. 15
7908
3
syysk. 24
46988