【发布时间】:2010-12-22 04:19:39
【问题描述】:
我有查询集:queryset = Status.objects.all()[:10]
模型Status 没有字段commentAmount 所以我会将它添加到查询集中的每个对象中:
for s in queryset:
s.commentAmount = s.getCommentAmount()
一切都很好,print s.commentAmount 显示了很好的结果,但是之后:
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(serializers.serialize("json", queryset))
return response
我没有在返回 JSON 文件时填写 commentAmount。我的错在哪里?
【问题讨论】:
标签: django json serialization django-models