单个json输出中有多个列表

时间:2018-09-03 19:28:28

标签: arrays json django list

所以我需要某种json格式的图表,我在视图中添加了以下内容

views.py

def booking_add_to_timeline(request):
data = Booking.objects.all().values(
    'booking_no',
    'arrival_date',
    'departure_date',
    )

data_list = list(data)

return JsonResponse({"data": data_list})

哪个给我以下输出:

JSON

{
  "data": [
    {
      "booking_no": "1",
      "arrival_date": "2018-09-03",
      "departure_date": "2018-09-10",
    },
    {
      "booking_no": "2",
      "arrival_date": "2018-09-12",
      "departure_date": "2018-09-19",
    }
  ]
}

我要添加另一个列表,以创建以下列表:

JSON

{
  "data": [
    {
      "booking_no": "1",
      "arrival_date": "2018-09-03",
      "departure_date": "2018-09-10",
    },
    {
      "booking_no": "2",
      "arrival_date": "2018-09-12",
      "departure_date": "2018-09-19",
    }
  ],
  "room": [
    {
      "nr": "102"
      "persons": "2"
    },
    {
      "nr": "103"
      "persons": "2"
    }
  ]
}

我试图通过组合list_all = data_list + room_list来添加注释列表,但这并不会创建单独的数组...

0 个答案:

没有答案