categoryList = list(Category.objects.raw(sql))
for index in range(len(categoryList)):
#categoryList[index]['count']='1'
如上,想在每个元素的key为count的里边赋值,我这么写好像不太对
建议先看看这个 Performing raw SQL queries. 查询出来的东西是RawQuerySet,里面的记录就是对应的模型实例。遍历这个RawQuerySet,在每个模型实例上执行应有的操作。
python
categoryList = Category.objects.raw(sql) for category in categoreList: category.count = 1