title: Django fill table column based on subdict key
body: <p>I have a dict in the following format:</p>
  
  <pre><code>{
    'P1': {'A': [1,10], 'B': [4,5], 'C': [8,12]},
    'P2': {'A': [1,10], 'E': [4,5], 'G': [8,12]},
    'P3': {'C': [1,10], 'D': [4,5], 'J': [8,12]}
  }
  </code></pre>
  
  <p>and an HTML table set-up like this:</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;th&gt;A&lt;/th&gt;
        &lt;th&gt;B&lt;/th&gt;
        &lt;th&gt;C&lt;/th&gt;
        &lt;th&gt;D&lt;/th&gt;
        &lt;th&gt;E&lt;/th&gt;
        &lt;th&gt;F&lt;/th&gt;
        &lt;th&gt;G&lt;/th&gt;
        &lt;th&gt;H&lt;/th&gt;
        &lt;th&gt;I&lt;/th&gt;
        &lt;th&gt;J&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  .
  .
  .
  </code></pre>
  
  <p>what I'm trying to do is outputting the P's letter on the correct "cell", basically the data should go in the correct letter, like this:</p>
  
  <pre><code>Player | A | B | C | D | E | F | G | H | I | J |
  P1     | 1 | 4 | 8 |   |   |   |   |   |   |   |
  P2     | 1 |   |   |   | 4 |   | 8 |   |   |   |
  P3     |   |   | 1 | 4 |   |   |   |   |   | 8 |
  </code></pre>
  
  <p>I tried this but failed:</p>
  
  <pre><code>{% for k,v in p_dataset.items %}
    &lt;tr&gt;
      &lt;td&gt;{{k}}&lt;/td&gt;
      {% for letter, vals in v.items %}
        &lt;td&gt;{% if letter == 'A' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'B' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'C' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'D' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'E' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'F' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'G' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'H' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'I' %}{{vals}}{% endif %}&lt;/td&gt;
        &lt;td&gt;{% if letter == 'J' %}{{vals}}{% endif %}&lt;/td&gt;
      {% endfor %}
    &lt;/tr&gt;
  {% endfor %}
  </code></pre>
  
  <p>but all I got where a lot of exceeding tds, how should I do this?</p>
  
  <p><em>Edit:</em> Thinking about it, perhaps I could add all the subkeys as empty and update them on the view, but is there another way?</p>