需要一些帮助来解决这个错误:
TypeError:“unicode”对象不支持项目分配
语言: menuDic [str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'][str(d.dish.id)] = {}
def getDishOfTheWeek():
menuDic = Ddict(dict)
for menu in Menus.select().where(state = True):
menuDic[str(menu.id)]={}
menuDic[str(menu.id)]['menuId']=menu.id
menuDic[str(menu.id)]['menuName']=menu.name
menuDic[str(menu.id)]['menuCountry']=menu.country.name
menuDic[str(menu.id)]['menuDishes']={}
for d in DishMenuRels.select().where(menu = menu.id).join(Dishes).join(DishTypes).order_by('name')
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)] = {}
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'] = d.dish.dishType.name
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'][str(d.dish.id)] = {}
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'][str(d.dish.id)]['dishId'] = d.dish.id
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'][str(d.dish.id)]['dishState'] = d.dish.name
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'][str(d.dish.id)]['dishType'] = d.dish.price
menuDic[str(menu.id)]['menuDishes'][str(d.dish.dishType.name)]['dishTypeName'][str(d.dish.id)]['dishName'] = d.dish.country.name
print json.dumps(menuDic, indent=5, sort_keys=True)
谢谢