I have a dictionary in python and I would like to insert values from it into a database to populate my Db quickly. Every time I try this I get the following error:
ValueError: too many values to unpack (expected 2)
Here's what I have:
def post(self, request):
image = "no image"
characters = {
"Auron": {'name': "Auron",
'stars': 4,
'image': image,
'series': "FF10"},
"Barret": {'name': "Barret",
'stars': 3,
'image': image,
'series': "FF7"},
"Zidane": {'name': "Zidane",
'stars': 5,
'image': image,
'series': "FF9"}
}
for key, value in characters:
number = 3
name = value.name
stars = value.stars
image = value.image
series = value.series
Characters.objects.create(id=number,name=name,stars=stars,image=image,series=series)
number += 1
return JsonResponse("Added all chars", safe=False)
Also, this code runs after an ajax call. Why is this happening? I have googled this but couldn't find anything similar to my problem. What could be causing this?
Thanks