looping over dictionaries

2010-02-14 Thread Madis
Why will this not work or how should i write it to work:

I have the following dictionary:
projects = {u'NetMinutes': {'chains': [u'Arendus', u'Uuslahendus']},
u'Veel': {'chains': []}}

Now in a template I want to iterate over them as follows:
{% for project in projects %}
{{ project }}
  {% for chain in project.chains %}
  -- {{ chain }}
  {% endfor %}
{% endfor %}

It iterates over the projects and prints out the project names but
will not iterate over the project.chains.
Maybe someone can give me some clues?

Regards,
Madis

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



nested lists

2010-02-13 Thread Madis
Could someone please explain what kind of a list would make this work:

{% for country in countries %}

{% for city in country.city_list %}

Country #{{ forloop.parentloop.counter }}
City #{{ forloop.counter }}
{{ city }}

{% endfor %}

{% endfor %}

Example is taken from is taken from http://www.djangobook.com/en/1.0/chapter04/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: dynamic variable in templates

2010-02-13 Thread Madis
http://push.cx/2007/django-template-tag-for-dictionary-access

This is basically what I'm looking for but I'm not sure that this is
the best way to do this.

On Feb 13, 8:55 pm, Madis <madisv...@gmail.com> wrote:
> Sorry for not explaining it more:
>
> chain is a dictionary of lists chains {'project1': ['item1', 'item2'],
> 'project2': ['item3']}
> So the key to the dictionary is basically a project name which I get
> when looping over the projects in the first loop. Now the second loop
> should be over the list of chains but the dictionary key is changing
> because the name of the project is changing but I can not find a way
> to do this in Django templates.
>
> On Feb 13, 8:47 pm, Karen Tracey <kmtra...@gmail.com> wrote:
>
>
>
> > On Sat, Feb 13, 2010 at 1:30 PM, Madis <madisv...@gmail.com> wrote:
> > > I'm trying to write the following but there seems to be no solution on
> > > the web for this.
>
> > > In a template:
> > > {% for project in projects %}
> > >  {% for chain in chains.project.name %} <--- project.name should be
> > > dynamic
> > >  {% endfor %}
> > > {% endfor %}
>
> > What is chains? What is chains.project? What do you mean project.name should
> > be dynamic? How does whatever happens when you try to render that template
> > differ from what you are expecting?
>
> > Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: dynamic variable in templates

2010-02-13 Thread Madis
Sorry for not explaining it more:

chain is a dictionary of lists chains {'project1': ['item1', 'item2'],
'project2': ['item3']}
So the key to the dictionary is basically a project name which I get
when looping over the projects in the first loop. Now the second loop
should be over the list of chains but the dictionary key is changing
because the name of the project is changing but I can not find a way
to do this in Django templates.

On Feb 13, 8:47 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sat, Feb 13, 2010 at 1:30 PM, Madis <madisv...@gmail.com> wrote:
> > I'm trying to write the following but there seems to be no solution on
> > the web for this.
>
> > In a template:
> > {% for project in projects %}
> >  {% for chain in chains.project.name %} <--- project.name should be
> > dynamic
> >  {% endfor %}
> > {% endfor %}
>
> What is chains? What is chains.project? What do you mean project.name should
> be dynamic? How does whatever happens when you try to render that template
> differ from what you are expecting?
>
> Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



dynamic variable in templates

2010-02-13 Thread Madis
I'm trying to write the following but there seems to be no solution on
the web for this.

In a template:
{% for project in projects %}
  {% for chain in chains.project.name %} <--- project.name should be
dynamic
  {% endfor %}
{% endfor %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.