def trouble_json_report(request):
    # 数据库中获取数据
    user_list = models.UserInfo.objects.filter()
    response = []
    for user in user_list:
        from django.db import connection, connections
        cursor = connection.cursor()
        cursor.execute("""select strftime('%%s',strftime("%%Y-%%m-01",ctime)) * 1000,count(id) from repository_trouble where processer_id = %s group by strftime("%%Y-%%m",ctime)""", [user.nid,])
        result = cursor.fetchall()
        print(user.username,result)
        temp = {
            'name': user.username,
            'data':result
        }
        response.append(temp)
    import json
    return HttpResponse(json.dumps(response))

 

posted on 2018-05-11 09:33  liweideblogs  阅读(102)  评论(0编辑  收藏  举报