odoo Qweb报告行按字母顺序排列 [英] odoo Qweb report lines in alphabetical order
问题描述
我为自己认为这是一件很愚蠢的事而发疯. 我需要按字母顺序渲染数组的结果:
I'm getting crazy for what I believe it is a really silly matter. I need to render the result of an array in alphabetical order:
<tr t-foreach="o.order_line" t-as="l">
<td>
<span t-field="l.name"/>
</td>
我应该使用SQL查询SELECT * FROM table ORDER BY
l.name DESC
吗?
但是它接缝太复杂了,我觉得有一个简单的条件可以正确地渲染它.
should I use a SQL query SELECT * FROM table ORDER BY
l.nameDESC
?
but it seams too complicated, I have the feeling there is a simple condition to render it correctly...
任何帮助深表感谢!谢谢!
any help highly appreciated! Thanks!
推荐答案
正如@Alessandro Ruffolo所写的那样,我刚刚遇到了这个问题,并且能够使用sorted
函数解决它.您必须将正确的参数传递给该函数,在您的情况下,它将是:
I have just faced this problem and I was able to solve it with sorted
function, as @Alessandro Ruffolo wrote. You have to pass the right parameters to that function, in your case it would be:
<tr t-foreach="o.order_line.sorted(key=lambda r: r.name, reverse=True)" t-as="l">
<td>
<span t-field="l.name"/>
</td>
...
</tr>
这篇关于odoo Qweb报告行按字母顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!