Thursday, September 18, 2014

Can I use a calculated value for a key to a dictionary?

I have some embed loops which iterate over league and division. I
want to print the teams in each. I obviously can't do what i tried in
line 19. Is there a way to calculate a key to a dictionary I want to
iterate over?

14{% for l in leagues %}
15 <h3>{{l}}</h3>
16 {% for d in divisions %}
17 <h4>{{d}}</h4>
18 <table>
19 {% for team in {{l}}{{d}} %}
20 <tr><td>{{team}}</td><td> {{ team.wins }}-</td><td>{{ team.losses
}}</td> </li>
21 {% endfor %}

Here is my context:

{u'ALW': [<Team: Oakland Athletics 1975>, <Team: Kansas City Royals
1975>, <Team: Texas Rangers 1975>, <Team: Minnesota Twins 1975>,
<Team: Chicago White Sox 1975>, <Team: California Angels 1975>],
u'ALE': [<Team: Boston Red Sox 1975>, <Team: Baltimore Orioles 1975>,
<Team: New York Yankees 1975>, <Team: Cleveland Indians 1975>, <Team:
Milwaukee Brewers 1975>, <Team: Detroit Tigers 1975>], u'NLE': [<Team:
Pittsburgh Pirates 1975>, <Team: Philadelphia Phillies 1975>, <Team:
New York Mets 1975>, <Team: St. Louis Cardinals 1975>, <Team: Chicago
Cubs 1975>, <Team: Montreal Expos 1975>], u'NLW': [<Team: Cincinnati
Reds 1975>, <Team: Los Angeles Dodgers 1975>, <Team: San Francisco
Giants 1975>, <Team: San Diego Padres 1975>, <Team: Atlanta Braves
1975>, <Team: Houston Astros 1975>]}
{'leagues': [u'AL', u'NL'], u'NLE': [<Team: Pittsburgh Pirates 1975>,
<Team: Philadelphia Phillies 1975>, <Team: New York Mets 1975>, <Team:
St. Louis Cardinals 1975>, <Team: Chicago Cubs 1975>, <Team: Montreal
Expos 1975>], u'NLW': [<Team: Cincinnati Reds 1975>, <Team: Los
Angeles Dodgers 1975>, <Team: San Francisco Giants 1975>, <Team: San
Diego Padres 1975>, <Team: Atlanta Braves 1975>, <Team: Houston Astros
1975>], 'year': u'1975', u'ALW': [<Team: Oakland Athletics 1975>,
<Team: Kansas City Royals 1975>, <Team: Texas Rangers 1975>, <Team:
Minnesota Twins 1975>, <Team: Chicago White Sox 1975>, <Team:
California Angels 1975>], u'ALE': [<Team: Boston Red Sox 1975>, <Team:
Baltimore Orioles 1975>, <Team: New York Yankees 1975>, <Team:
Cleveland Indians 1975>, <Team: Milwaukee Brewers 1975>, <Team:
Detroit Tigers 1975>], 'divisions': [u'E', u'W']}

--
Joel Goldstick
http://joelgoldstick.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPM-O%2ByfS1BfDCEKYbJOwctjtd8JkJ04OS71iv4dVtVRQf8KRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment