I wish for a "less than" and "greater than" in templates

1,012 views
Skip to first unread message

Michael Lake

unread,
Mar 21, 2007, 11:55:04 PM3/21/07
to django...@googlegroups.com
Hi all

I'm wishing for a "less than" and "greater than" in templates.
The mailing list has this on the matter:

On 31-Aug-06
>> Is it possible to make "less than" and "greater than" comparisons in
>> templates?
>> I was trying to do something similar to this, but without success:
>> {% if list|length > max_list_length %}
>> Exceeded by {{ list|length - max_list_length }} items
>> {% endif %}
>
> write your own tag - someone has done it, you can see it in this file:
>
> http://nrcfosshelpline.in/code/browser/trunk/web/templatetags/
> base_utils.py
>
> class CompareNode near the end

But that link above no longer works.
Does anyone have some code for this?
I looked in Django Snippets and didn't find such a snippet.

Mike
--
Michael Lake

Kenneth Gonsalves

unread,
Mar 22, 2007, 1:06:34 AM3/22/07
to django...@googlegroups.com

On 22-Mar-07, at 9:25 AM, Michael Lake wrote:

>> write your own tag - someone has done it, you can see it in this
>> file:
>>
>> http://nrcfosshelpline.in/code/browser/trunk/web/templatetags/
>> base_utils.py
>>
>> class CompareNode near the end
>
> But that link above no longer works.

works now - thanks for the heads up on this

--

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/


Michael Lake

unread,
Mar 22, 2007, 1:11:01 AM3/22/07
to django...@googlegroups.com
Kenneth Gonsalves wrote:

> On 22-Mar-07, at 9:25 AM, Michael Lake wrote:
>>>write your own tag - someone has done it, you can see it in this
>>>file:
>>>
>>>http://nrcfosshelpline.in/code/browser/trunk/web/templatetags/
>>>base_utils.py
>>>
>>>class CompareNode near the end
>>
>>But that link above no longer works.

> works now - thanks for the heads up on this

Thanks for that Kenneth.
The code there looks like just what I need.

Mike
--
Michael Lake

limodou

unread,
Mar 22, 2007, 1:29:39 AM3/22/07
to django...@googlegroups.com
You can also use PyIf tag(written by me) to do that.

http://www.djangosnippets.org/snippets/12/

And it can support any python expression. So it's more general I think.

--
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

Michael Lake

unread,
Mar 22, 2007, 2:28:49 AM3/22/07
to django...@googlegroups.com
limodou wrote:
> You can also use PyIf tag(written by me) to do that.
> http://www.djangosnippets.org/snippets/12/
> And it can support any python expression. So it's more general I think.

And it's short and understandable. I like it too.
Thanks

Mike
--
Michael Lake

Reply all
Reply to author
Forward
0 new messages