I have the following class based view in which I perform to queryset:
model = PatientProfile
template_name = 'patient_detail.html'
context_object_name = 'patientdetail'
def get_context_data(self, **kwargs):
context=super(PatientDetail, self).get_context_data(**kwargs)
queryset= RehabilitationSession.objects.filter(patient__slug=self.kwargs['slug']){% extends "base.html" %}
{% block content %}
{{patient_session_data}}
{% endblock content %}<QuerySet [<RehabilitationSession: Hernando Zambrano Cuellar>, <RehabilitationSession: Hernando Zambrano Cuellar>, <RehabilitationSession: Hernando Zambrano Cuellar>]>
I want access to specific attibute named upper_extremity of my RehabilitationSession model, then I make this:
{% for upperlimb in patient_session_data %}
{{upperlimb.upper_extremity}}
{%endfor%}
This mean, three times the value, because my queryset return me three objects. This is logic.
For access to value of a separate way I make this in my template:
{{patient_session_data.0.upper_extremity}}
And I get:
Izquierda
My goal
I unknown the amount of querysets objects RehabilitationSession that will be returned by the queryset executed in my PatientDetail
cbv, because the number is dynamic, may be any amount of objects returned.
I want read the value content of each patient_session_data upper_extremity and accord to the value make something in my template,
But I want read it of a dynamic way,without use {{patient_session_data.<0-1-2-3>.
upper_extremity}}
For example in a hypotetical case:
#if all objects returned have same value in upper_extremity
{% if patient_session_data.upper_extremity == 'Izquierda' %}
<div class="col-md-10">
<h5>Segmentos corporales a tratar</h5>
<small>Codo - mano - falange</small>
</div>
{%endif%}
I think that I have count the amount of objects and make with them some actions, because I don't have clear ...
How to can I access of a individual way to the objects returned of a dynamic way without matter the objects number returned?