Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
4778 Visninger

Hello,

I would like to print a one2many fields separated by comma, but always I have a comma more.

So how can I use variables in a Qweb loop to avoid this problem?

this is my code :

<span>(
</span>
<span t-foreach="o.hijos_ids" t-as="i">

<span t-field="i.number"/>
<span>,</span>
</span>
<span>)</span>

this is the result:

(nbr1,nbr2,)

Thank you

Best regards

Avatar
Kassér
Bedste svar

<span>(
</span>
<span t-foreach="o.hijos_ids" t-as="i">

<span t-field="i.number"/>
<span t-if="not i.number == o.hijos_ids[-1].number">,</span>
</span>
<span>)</span>

Avatar
Kassér
Bedste svar

if you really want to use qweb for, you can use

t-if='i_last'


but you should probably use python method similar to  

<t t-esc="', '.join(o.hijobs_ids.mapped('number'))"/>
Avatar
Kassér