On Wed, Jun 24, 2009, James Gregory <james....@gmail.com> wrote:

>> >>> I have a template in which I would like to do the following:
>>
>> >>> {% for item in loop %}
>> >>>     {% if [previous item].condition %}
>> >>>         <li>item.name</li>
>> >>>     {% endif %}
>> >>> {% endfor %}
>>
>> >>> In other words, I want to do something with an item in the loop  
>> >>> based on
>> >>> whether the *previous* item has some condition set.

>> Or zip the list with itself (with offsets where needed) and use that,  
>> either for the transformation or for the display.

Thanks for all the suggestions. We realised that this isn't something
that can be handled in a template.

What we did was put it in a function in the model:

    def ancestry_for_address(self):
        ancestors = []
        showparent = self.display_parent
        for item in self.get_ancestors(ascending = True):
            if showparent:
                ancestors.append(item)
            showparent = item.display_parent

That way we get a list of the items, and skip over the ones we don't want.

(We need this to construct our institutional addresses. I am in the It
Office of the School of Medicine at Cardiff University. If I used the
correct names of those, my address would end up being:

    IT Office
    Cardiff University School of Medicine
    Cardiff University

which is obviously silly.

So, now we can tell the system that "Cardiff University School of
Medicine" doesn't need "Cardiff University" to follow it. On the other hand:

    Human Resources
    Cardiff University

is correct, so "Human Resources" will ask for its parent.)

Daniele




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

Reply via email to