'create nested json from the ouput of two queries django

My code snippet looks like this:

views.py

def get_milestonebased_deals(request):

           cursor = connection.cursor()
           cursor.execute("SELECT id,deal_title, milestone_order_id  from myapp_milestone")
           row = cursor.fetchall()
           cursor2=connection.cursor()
           cursor2.execute("select id, title, deal_milestone_id created from myapp_deals")
           row2=cursor2.fetchall()
           data_dict = ValuesQuerySetToDict(row)
           data_json = json.dumps(data_dict)
           data_dict2 = ValuesQuerySetToDict(row2)
           data_jsonn = json.dumps([data_dict2])
           return json_response({
                               'status':data_json,
                               
                          })

I want to create json object as below from the above function:

[{
"id":"1",
"title":"Lead",
"milestone":[{
    "id":"1",
    "deal_title":"Staff",
    "created":"date"
    },
    {
    "id":"2",
    "deal_title":"Staff2",
    "created":"date"
    },
    {"id":"1",
    "deal_title":"Staff3",
    "created":"date"
    }]
},
{"id":"2",
"title":"Lead2",
"milestone":[{
    "id":"1",
    "deal_title":"employee",
    "created":"date"
    },
    {
    "id":"2",
    "deal_title":"employee3",
    "created":"date"
    }]
}]

Can anyone suggest does it possible, if so then how?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source