无法解析字段ID django tastypie mongoengine

时间:2013-01-28 10:14:40

标签: django mongoengine tastypie

看来这个错误不依赖于我的代码 我尝试一起使用mongodb和mysql而不使用django-norel

{"error_message": "Cannot resolve field \"id\"", "traceback": "Traceback (most recent call last):\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 192, in wrapper\n    response = callback(request, *args, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 397, in dispatch_list\n    return self.dispatch('list', request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie_mongoengine/resources.py\", line 339, in dispatch\n    return super(MongoEngineResource, self).dispatch(request_type, request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 427, in dispatch\n    response = method(request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 1033, in get_list\n    to_be_serialized = paginator.page()\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/paginator.py\", line 155, in page\n    count = self.get_count()\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/paginator.py\", line 110, in get_count\n    return self.objects.count()\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 1033, in count\n    return self._cursor.count(with_limit_and_skip=True)\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 607, in _cursor\n    self._cursor_obj = self._collection.find(self._query,\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 588, in _collection\n    self._ensure_indexes()\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 490, in _ensure_indexes\n    if index_types and '_types' in self._query and not types_indexed:\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 389, in _query\n    self._mongo_query = self._query_obj.to_query(self._document)\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 212, in to_query\n    query = query.accept(QueryCompilerVisitor(document))\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 277, in accept\n    return visitor.visit_query(self)\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 169, in visit_query\n    return QuerySet._transform_query(self.document, **query.query)\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 727, in _transform_query\n    fields = QuerySet._lookup_field(_doc_cls, parts)\n\n  File \"/usr/local/lib/python2.7/dist-packages/mongoengine/queryset.py\", line 680, in _lookup_field\n    % field_name)\n\nInvalidQueryError: Cannot resolve field \"id\"\n"}

class RssItem(Document):
    rss=fields.StringField()
    title=fields.StringField()
    description=fields.StringField()

class RssItemsResource(resources.MongoEngineResource):
   class Meta:
        queryset = RssItem.objects.all()
        resource_name = 'rssitem'
        include_resource_uri=False
        authorization= customOauth2Authorization()
        collection = "items" # collection name

1 个答案:

答案 0 :(得分:-1)

它是关于我在build_filters中使用id 删除该行并添加

ID = StringField(db_field = “_ ID”)

meta = {
        'collection': 'items',
         'allow_inheritance': False,
         }

记录所有已解决的问题