I need to convert JSON data to django model.
This is my JSON data
{
"data": [
{
"id": "20ad5d9c-b32e-4599-8866-a3aaa5ac77de",
"name": "name_1"
},
{
"id": "7b6d76cc-86cd-40f8-be90-af6ced7fec44",
"name": "name_2"
},
{
"id": "b8843b1a-9eb0-499f-ba64-25e436f04c4b",
"name": "name_3"
}
]
}
This is my django method
def get_titles():
url = 'http://localhost:8080/titles/'
r = requests.get(url)
titles = r.json()
print(titles['data'])
What I need is convert the JSON into an instance of the model and pass it to the template. Please let me know how to convert JSON to Model.