title: How to add Python data to HTML table
body: <p>I need to have following table format in HTML:
  <a href="https://i.stack.imgur.com/MQFOa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MQFOa.jpg" alt="enter image description here"></a></p>
  
  <p>My question is, how I should organize my Python data correctly so that I can implement this following table format in a clean, Pythonic way. All images belong to the certain version, thus it's important that image is in the right column (order matters). And some versions don't have all (or any) images so in that case, I'll check if "image == None" and show "?" etc. instead of the image. Thus, also 'empty' slots should be saved to data.</p>
  
  <p>Note: I'm doing this with Django and I use Django templates to render this. Ideally, I could do something like following in the template:</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        {% for version in data.versions %}
        &lt;th&gt;{{ version }}&lt;/th&gt;
        {% endfor %}
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      {% for image in data.images %}
      &lt;tr&gt;
        {% for file in image.files %}
          {% if file == None %}
          &lt;td&gt;No image&lt;/td&gt;
          {% else %}
          &lt;td&gt;{{ file }}&lt;/td&gt;
          {% endif %}
        {% endfor %}
      &lt;/tr&gt;
      {% endfor %}
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Update: the problem is really how to organize data correctly in the backend. I need to manually initialize a list of versions (Version1, Version2, etc.) I want to put to data and create columns for those. Ordering is important so I need to keep that. Then I'll search for certain Objects which have X amount of images, which all have a certain version. Then I need to loop over those objects (for object in objects) and loop over images of the certain object (for image in object.images) and I should append each image to the column of certain version (add to column where "key" etc. == image.version). If there is no image for certain column, then value should be "None" etc.</p>
  
  <p>I could implement this with list of lists for example:</p>
  
  <pre><code>data = [
      ['Version1', 'Version2', etc.],
      ['image',None, etc.],
      ['image', 'image', etc.],
      etc.
  ]
  </code></pre>
  
  <p>But I'm pretty sure there is a better way to implement that in Python. So any better suggestions are very welcome.</p>
  
  <p>Update 2: Django models could be like following:</p>
  
  <pre><code>class Version(models.Model):
      name = models.CharField(max_length=255)
  
  
  class Image(models.Model):
      file = models.ImageField(upload_to='images')
      version = models.ForeignKey(Version)
  
  
  class Object(models.Model):
      images = models.ManyToManyField(Image)
  </code></pre>