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.
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:
reactions_detail.html
{% extends 'Recon/Base.html' %}{% load static %}{% block title %}Reaction
Details{% endblock %}{% block body %}<h1>{{ reactionsmeta.id }}</h1><h2>{{
reactionsmeta.name}}</h2><!-- Left Album Info --><div class="col-sm-4 col-md-3">
<div class="panel panel-default">
<div class="panel-body">
<a href="{% url 'detail_reaction' reactionsmeta.id %}">
{% if reactionsmeta.id %}
<img src="{% static
"Recon/images/Logo-Technische-Universiteit-Eindhoven.jpg" %}"
class="img-responsive">
{% else %}
<h3>No image to display</h3>
{% endif %}
</a>
<h1>{{ reactionsmeta.id }} <small>{{ reactionsmeta.name
}}</small></h1>
</div>
</div></div>
[image: index.html] <https://i.stack.imgur.com/kscEz.jpg>
views.pyfrom django.views import genericfrom .models import
Reactionsmeta,Metabolites,Reactionsfrom 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
How can I write the loop in reaction_detail.html???
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/76028827-99ad-43a3-8bb1-831f8f6df183%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.