title: Having trouble writing loops in django template
body: <p>Hello guys I am currently working on django views and templates and met some problems.
  I have a model named 'metabolites', which contains: id, name, compartment, charge and formula 5 components.
  I have another model named 'Reactionsmeta', which contains: id(reactions), name, metabolie1, metabolite2, .... metabolite6. The table of this model is not filled complete, because sometimes one id corresponds to 5 metabolites, but sometimes even 20.</p>
  
  <p>I write a template which can displays all the reaction, when I click on the reaction and enter the detail page, I also want to display the metabolites that involve in this reactions. My views.py and templates are written as below:</p>
  
  <pre><code>reactions_detail.html
  
  {% extends 'Recon/Base.html' %}
  {% load static %}
  {% block title %}Reaction Details{% endblock %}
  {% block body %}
  &lt;h1&gt;{{ reactionsmeta.id }}&lt;/h1&gt;
  &lt;h2&gt;{{ reactionsmeta.name}}&lt;/h2&gt;
  &lt;!-- Left Album Info --&gt;
  &lt;div class="col-sm-4 col-md-3"&gt;
      &lt;div class="panel panel-default"&gt;
          &lt;div class="panel-body"&gt;
              &lt;a href="{% url 'detail_reaction' reactionsmeta.id %}"&gt;
                  {% if reactionsmeta.id %}
                      &lt;img src="{% static "Recon/images/Logo-Technische-Universiteit-Eindhoven.jpg" %}" class="img-responsive"&gt;
                  {% else %}
                      &lt;h3&gt;No image to display&lt;/h3&gt;
                  {% endif %}
              &lt;/a&gt;
              &lt;h1&gt;{{ reactionsmeta.id }} &lt;small&gt;{{ reactionsmeta.name }}&lt;/small&gt;&lt;/h1&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kscEz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kscEz.jpg" alt="index.html"></a></p>
  
  <pre><code>views.py
  from django.views import generic
  from .models import Reactionsmeta,Metabolites,Reactions
  from django.shortcuts import render
  
  
  class IndexView(generic.ListView):
  template_name = 'Recon/index.html'
  context_object_name = 'Reactions_object'
  
  def get_queryset(self):
      return Reactionsmeta.objects.all()
  
  
  class DetailsView(generic.DetailView):
  model = Reactionsmeta
  template_name = 'Recon/reactions_detail.html'
  
  def get_context_data(self, **kwargs):
      context = super(DetailsView, self).get_context_data(**kwargs)
      context['metabolite'] = Metabolites.objects.all()
      context['reactions'] = Reactions.objects.all()
  
      # And so on for more models
      return context
  </code></pre>
  
  <p>How can I write the loop in reaction_detail.html???</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <pre><code>class Metabolites(models.Model):
  id = models.CharField(primary_key=True, max_length=255)
  name = models.CharField(max_length=255, blank=True, null=True)
  compartment = models.CharField(max_length=255, blank=True, null=True)
  charge = models.CharField(max_length=255, blank=True, null=True)
  formula = models.CharField(max_length=255, blank=True, null=True)
  notes = models.CharField(max_length=255, blank=True, null=True)
  
  class Meta:
      managed = False
      db_table = 'Metabolites'
  
  class Reactionsmeta(models.Model):
  id = models.CharField(primary_key=True, max_length=255)
  name = models.CharField(max_length=255, blank=True, null=True)
  metabolite1 = models.ForeignKey('Metabolites', db_column='metabolite1', 
  blank=True, null=True, on_delete=models.CASCADE)
  stoichiometry1 = models.IntegerField(blank=True, null=True)
  metabolite2 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry2 = models.IntegerField(blank=True, null=True)
  metabolite3 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry3 = models.CharField(max_length=255, blank=True, null=True)
  ......
  stoichiometry55 = models.CharField(max_length=255, blank=True, null=True)
  metabolite56 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry56 = models.CharField(max_length=255, blank=True, null=True)
  metabolite57 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry57 = models.CharField(max_length=255, blank=True, null=True)
  metabolite58 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry58 = models.CharField(max_length=255, blank=True, null=True)
  metabolite59 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry59 = models.CharField(max_length=255, blank=True, null=True)
  metabolite60 = models.CharField(max_length=255, blank=True, null=True)
  stoichiometry60 = models.CharField(max_length=255, blank=True, null=True)
  
  class Meta:
      managed = False
      db_table = 'ReactionsMeta'
  </code></pre>