It sounds like you are looking for a tag that would let you be more 
concise about this.  Something like:

    {% for pa in pub.pubauthor_set.all %}
    <a href="{{ pa.author.url }}">{{ pa.author }}</a>{% nth
    forloop.revcounter "" "and" "," %}
    {% endfor %}

Where the nth tag works like this: its first argument is an integer 
(call it n).  The rest of the arguments are choices.  The nth one is 
used, but the last one is used if the n is more than the number of 
choices.  It's a little funny to have to list them in the wrong order 
like I did, but that's because I used revcounter for n.

The nth tag doesn't exist yet, but does it look like what you are asking 
for?

--Ned.
http://nedbatchelder.com/blog

toomim wrote:
> On Feb 6, 11:05 pm, toomim <[EMAIL PROTECTED]> wrote:
>   
>> I don't understand, how do I get {{sep}} to change from ',' to 'and'
>> and then to the empty string in the last 2 iterations of the loop,
>> without using a bunch of if statements? (And since we're using
>> variables, a {% where %} clause?)
>>     
>
> Here's my code, if it helps:
>
>       {% for pubauthor in pub.pubauthor_set.all %}
>       <a href="{{ pubauthor.author.homepage_url }}">{{ pubauthor.author }}</
> a>{% if forloop.last %}{% else %}{% ifequal forloop.revcounter 2 %}
> and {% else %},
>       {% endifequal %}
>       {% endif %}
>       {% endfor %}
>
> >
>
>   

-- 
Ned Batchelder, http://nedbatchelder.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to