将QuerySet 转换为数组:直接使用python的list()函数,list()与str()、int()类似

list(). 对 QuerySet 应用 list() 方法,就会运行查询。例如:

1
entry_list = list (Entry.objects. all ())


c_set = modelinstance.objects.all().distinct().values('id', data=F(fieldname))
response = list(c_set)
return HttpResponse(json.dumps({'rows': response}), content_type="application/json")




猜你喜欢

转载自blog.csdn.net/qq_27361945/article/details/80237730
今日推荐