我正在尝试制作一个如下所示的
JSON:
[ { "num_of_followers": 2,"name": "Math 140","created_by": "aaa" } ]
问题是我真的不明白如何获取一个特定数据库对象的值列表(另一个词我怎样才能得到整行)
@csrf_exempt def create_subject(request,subject): subject,created= Subjects.objects.get_or_create( name=subject,user=request.user,created_by=request.user) list = [] columns = [Subjects._Meta.get_all_field_names()] row = ???????? for value in row: record = dict(zip(columns,value)) list.append(record) result = simplejson.dumps(list,indent=4) return HttpResponse(result)