I am having following data:
[{
'mp': [ < MpbMealPlan: MpbMealPlan object > , < MpbMealPlan: MpbMealPlan object > ],
'user': [ < User: mpowner mpowner > ]
}, {
'mp': [ < MpbMealPlan: MpbMealPlan object > , < MpbMealPlan: MpbMealPlan object > ],
'user': [ < User: kvermaOwner Owner > ]
}]
I want to iterate it in my django template. As shown these are two records with 2 keys in each(mp and user) each record belong to particular user. So I wnat to it such that I get mps of user and detail of user. But when I try to iterate it as explained in below answer or any other answer through out SO I every time get bizarre results. mp can contains further multiple records but I am stuck at first iteration only. I am very new to python , it is my 3rd day working. Any guidance would save my day.
As soon as I apply below:
{% for contributor in contributors.details %}
{{ contributor }}
{% endfor %}
and I got this Output which break downs the structure:
{
'mp': [ < MpbMealPlan: MpbMealPlan object > , < MpbMealPlan: MpbMealPlan object > ],
'user': [ < User: mpowner mpowner > ]
} {
'mp': [ < MpbMealPlan: MpbMealPlan object > , < MpbMealPlan: MpbMealPlan object > ],
'user': [ < User: kvermaOwner Owner > ]
}
One query: Is it even possible to get desired results from the data I have. I want to iterate it to get mp and user and then I want to iterate mp to get multiple records within it. As whenever I tried iterating up to any level I get all the records so keys "mp and user" are not solving my purpose.
I don't want to waste any one's time here. I have updated the question. Thanks for answers till now. Update:
Following is the method I used and got desired results:
{% for contributor in contributors.details %}
{% for user in contributor.user %}
{{ user }}
<br>
{% for mp in contributor.mp %}
{{ mp.mp_name }}
<br>
{% endfor %}
{% endfor %}
{% endfor %}
Results:
user:mpowner mpowner
mp:Fresh & Healthy
mp:evening snacks
user:kvermaOwner Owner
mp:Fresh & Healthy
mp:Energizing
At last I got desired output with C14L's help (Amazing guidance). Thanks to "ajabdelaziz" and others too.