Django 2.2 //
python 3.6 //
У меня есть контекст, созданный с помощью комбинации «список» и «словарь».
Структура данных показана ниже.
{
"Mike":[
{
"month":"2020-02",
"consult_counts_total":2,
"consult_counts_total_uid":2
},
{
"month":"2020-01",
"consult_counts_total":4,
"consult_counts_total_uid":7
},
{
"month":"2019-12",
"consult_counts_total":6,
"consult_counts_total_uid":1
}
],
"Jaden":[
{
"month":"2020-02",
"consult_counts_total":8,
"consult_counts_total_uid":12
},
{
"month":"2020-01",
"consult_counts_total":23,
"consult_counts_total_uid":11
},
{
"month":"2019-12",
"consult_counts_total":2,
"consult_counts_total_uid":19
}
],
"Sarah":[
{
"month":"2020-02",
"consult_counts_total":2,
"consult_counts_total_uid":2
},
{
"month":"2020-01",
"consult_counts_total":4,
"consult_counts_total_uid":7
},
{
"month":"2019-12",
"consult_counts_total":6,
"consult_counts_total_uid":1
}
],
"John":[
{
"month":"2020-02",
"consult_counts_total":1,
"consult_counts_total_uid":0
},
{
"month":"2020-01",
"consult_counts_total":2,
"consult_counts_total_uid":7
},
{
"month":"2019-12",
"consult_counts_total":5,
"consult_counts_total_uid":1
}
]
}
Я пытаюсь отобразить эти данные через al oop в шаблоне.
Сначала я попробовал. Это показывает хороший результат.
{% for foo in context_data %}
<p>{{ foo }}</p>
{% endfor %}
# result
Mike
Jaden
Sarah
John
Но я не могу получить больше данных о глубине.
Например, я хочу получить все месяцы Майка (2020-02, 2020-01, 2019 -12)
Вторая попытка ..
{% for foo in context_data %}
<p class="big">This is {{ foo }}'s months.</p>
{% for foo2 in foo %}
<p class="small">{{ foo2.months }}</p>
{% endfor %}
{% endfor %}
# but it's showing nothing
Третья попытка ..
{% for foo in context_data %}
<p class="big">This is {{ foo }}'s months.</p>
{% for foo2 in foo %}
<p class="small">{{ foo2 }}</p>
{% endfor %}
<br>
{% endfor %}
# result
This is Mike's months.
M
i
k
e
Третий код зацикливания строки "Майк" .. не под данными Майка.
Я ожидаю, что буду показывать вот так.
This is Mike's months.
2020-02
2020-01
2019-12
This is Jaden's months.
2020-02
2020-01
2019-12
This is Sarah's months.
2020-02
2020-01
2019-12
This is John's months.
2020-02
2020-01
2019-12
Как я могу это сделать?