开发者

'MyModel' object is not iterable

I getting 'YesNo' object is not iterable. ..apps/wadofstuff/django/serializers/base.py in serialize, line 44

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

But i used something like this, but with query set containing several instances of one of my model. Has someone has any tips?


You could just wrap your instance in a list:

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


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

This will return serializable object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜