Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9976 Lượt xem

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>

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I found the answer:

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

Update, or:

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



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can write, also this,

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

FOO

</t>

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 24
3334
3
thg 10 16
6972
1
thg 12 23
26962
1
thg 3 15
7897
3
thg 9 24
46967