{
"width": 12,
"height": 180,
"full_row": True,
"url_name": "frame_empty_frame",
"url_action_name": "metrics_survey",
"content": {
"view": custom_views.MonitorMetrics,
"view_params": {
"model": custom_models.Monitor,
"group_by": ["survey", "surveygroup__name"],
"aggregations": [
{
"function": "Count",
"value": "id",
}, # annotation
],
},
},
},
class MonitorMetrics(module_views.Kpi):
def set_context(self, request):
datasets = []
surveys = []
surveygroup__names = []
queryset = self.get_queryset()
if queryset:
for item in queryset:
if item["survey"]:
surveys.append(item["survey"])
if item["surveygroup__name"]:
surveygroup__names.append(item["surveygroup__name"])
datasets.append(
{
"width": 6,
"value": "Surveys",
"label": ", ".join(sorted(set(surveys))),
}
)
datasets.append(
{
"width": 6,
"value": "Survey Groups",
"label": ", ".join(sorted(set(surveygroup__names))),
}
)
self.context = {"metrics_new": datasets}
This custom_views can generate the card with the surveys and survey group.