在我的应用程序中,我具有以下注释语句:
TestQuestion.objects.filter(test__owner=self.user, test__complete=True).values('question__concept__name', 'chosen_answer__is_correct').annotate(dcount=Count('question__concept__name'))
哪个将返回JSON输出,如下所示:
"concept_questions_completed": [
{
"question__concept__name": "Math",
"chosen_answer__is_correct": false,
"dcount": 8
},
{
"question__concept__name": "Math",
"chosen_answer__is_correct": true,
"dcount": 9
},
.....
]
但是,想知道是否有任何方法可以转换输出以使其在以后使用时更容易。这样看起来像这样:
"concept_questions_completed": [
"Math":
{
true:
{
"dcount": 9
},
false:
{
"dcount": 8
}
},
...
]