【发布时间】:2015-03-04 01:40:02
【问题描述】:
我的 Django QuerySet 有这个结果(JSON):
{
"high": [{
"counthigh": 27,
"brgy_locat": "Barangay 6"
}, {
"counthigh": 3,
"brgy_locat": "Mabini"
}],
"medium": [{
"brgy_locat": "Barangay 6",
"countmedium": 31
}, {
"brgy_locat": "Tolosa",
"countmedium": 9
}],
"low": [{
"brgy_locat": "Barangay 12",
"countlow": 29
}, {
"brgy_locat": "Mabini",
"countlow": 25
}, {
"brgy_locat": "Barangay 9",
"countlow": 35
}]
}
我想按 brgy_locat 及其值对其进行分组:
brgy_locat | countlow | countmedium | counthigh
主要是因为,我使用的是数据表。
顺便说一句,这是我的观点.py:
response_data = {}
response_data["medium"] = list(BuildingStructure.objects.filter(geom__intersects=getgeom_medium).values( 'brgy_locat').annotate(countmedium=Count('brgy_locat')))
response_data["high"] = list(BuildingStructure.objects.filter(geom__intersects=getgeom).values('brgy_locat').annotate( counthigh=Count('brgy_locat')))
response_data["low"] = list(BuildingStructure.objects.filter(geom__intersects=getgeom_low).values('brgy_locat').annotate( countlow=Count('brgy_locat')))
return HttpResponse(json.dumps(response_data), content_type='application/json')
【问题讨论】:
-
如何从 QuerySet 中获取 JSON?你用的是什么数据库?
-
来自 HttpResponse,我正在使用 PostgreSQL
标签: json django jquery-datatables