2011-08-01 163 views
3

我得到'YesNo' object is not iterable..apps/wadofstuff/django/serializers/base.py in serialize, line 44'MyModel'對象不可迭代

def yes_add(request, id): 
    if request.is_ajax: 
     form = YesNoForm(request.POST) 
     if form.is_valid(): 
      content = form.cleaned_data['content'] 
      user = request.user 
      value = 'yes' 
      item = Item.objects.get(id=id) 
      yes = YesNo(value=value, user=user, item=item, content=content) 
      yes.save() 
      response = HttpResponse() 
      response['Content-Type'] = "text/javascript" 
      response.write(serializers.serialize("json", yes)) 
      return response 

但我用這樣的事情,但包含我的模型之一的幾個實例查詢集。有人有任何提示嗎?

回答

13

你可以只換你比如在列表:

response.write(serializers.serialize("json", [yes]) 
+0

而且一切都很好。謝謝。 – krzyhub

4
item = Item.objects.filter(id=id) 

這將返回序列化對象。