views:

53

answers:

1

I have Queryset:
queryset = Status.objects.all()[:10]
Model Status hasn't got field commentAmount so I would add it to every object in Queryset:

for s in queryset:
 s.commentAmount = s.getCommentAmount()

All is fine, print s.commentAmount shows good results, but after:

response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(serializers.serialize("json", queryset))

return response

I have not field commentAmount in returning JSON file. Where is my mistake?

+2  A: 

The reason commentAmount is not showing up is because when Django does the serialization, it loops through the fields declared on the model and only those fields.

Consider looping through your queryset in a template and creating the json manually or using another serialization tool such as simplejson.

sheats