响应时Django MongoDB Tastypie错误

时间:2014-08-28 22:41:46

标签: python pymongo tastypie

不知道是什么问题。我所指的博客有相同的步骤,多次交叉检查。

我有models.py

class Tag(models.Model):
    tag_name = models.CharField(max_length=50, unique=True)

现在我做了syncdb我得到了MongoDB设置。

from tastypie.resources import ModelResource
from models import Article, Tag

class ArticleResource(ModelResource):
    class Meta:
        Tag.objects.create(
        tag_name='Python'
        )
        queryset = Tag.objects.all()
        resource_name = 'articles'

上面的类将数据添加到我的MongoDB中,但是在显示响应时会出现错误,这实际上是不可理解的:

{"error_message": "invalid literal for int() with base 10: '53ffae131c20d8048c03cd63'", "traceback": "Traceback (most recent call last):\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/resources.py\", line 201, in wrapper\n response = callback(request, *args, **kwargs)\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/resources.py\", line 432, in dispatch_list\n return self.dispatch('list', request, **kwargs)\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/resources.py\", line 464, in dispatch\n response = method(request, **kwargs)\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/resources.py\", line 1299, in get_list\n bundles.append(self.full_dehydrate(bundle, for_list=True))\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/resources.py\", line 854, in full_dehydrate\n bundle.data[field_name] = field_object.dehydrate(bundle, for_list=for_list)\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/fields.py\", line 135, in dehydrate\n return self.convert(current_object)\n\n File \"/home/django/env/bheeku/local/lib/python2.7/site-packages/tastypie/fields.py\", line 234, in convert\n return int(value)\n\nValueError: invalid literal for int() with base 10: '53ffae131c20d8048c03cd63'\n"}

到底出了什么问题?

然而它正在回归

{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 0}, "objects": []}

表格中没有数据。

0 个答案:

没有答案