if >, if >= in templates?

0 views
Skip to first unread message

Steven Armstrong

unread,
Jun 25, 2006, 4:13:12 PM6/25/06
to django...@googlegroups.com
Hi

I've got the following in my template:

{% if reference_set.count %}
<ul>
{% for reference in reference_set.all|slice:":5" %}
<li><a href="{{ reference.website }}">{{ reference.name }}</a></li>
{% endfor %}
</ul>
{% endif %}


If there are more then 5 references I'ld like to show a 'more' link that
leads to a list of all references.

Something like (pseudocode):
{% if reference_set.count > 5 %}
<a href="/path/to/references">more</a>
{% endif %}


Anybody know how to do that?
Or am I missing something obvious?

Don Arbow

unread,
Jun 25, 2006, 4:50:00 PM6/25/06
to django...@googlegroups.com
On Jun 25, 2006, at 1:13 PM, Steven Armstrong wrote:


If there are more then 5 references I'ld like to show a 'more' link that 
leads to a list of all references.

Something like (pseudocode):
{% if reference_set.count > 5 %}
<a href="/path/to/references">more</a>
{% endif %}


Anybody know how to do that?
Or am I missing something obvious?


Not sure if it works, but off the top of my head, what I would try is this:

{% if reference_set.all|slice:"5:" %}

should return true if the slice produces anything past the 5th element.

Don

Ivan Sagalaev

unread,
Jun 26, 2006, 1:26:31 AM6/26/06
to django...@googlegroups.com
Don Arbow wrote:
> Not sure if it works, but off the top of my head, what I would try is this:
>
> {% if reference_set.all|slice:"5:" %}

Not exactly this. Here a DB (Postgres at least) will complain that it
can't set OFFSET without LIMIT. This would work:

{% if reference_set.all|slice:"5:6" %}

Steven Armstrong

unread,
Jun 26, 2006, 11:45:49 AM6/26/06
to django...@googlegroups.com

Using sqlite, django also complained with AssertionError 'offset'
is not allowed without 'limit'.

Ivan's variation does the trick.

Thanks to both of you :)

cheers
Steven

Reply all
Reply to author
Forward
0 new messages