1

看来这个错误不取决于我的代码我尝试在不使用 django-norel 的情况下一起使用 mongodb 和 mysql

{"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
4

1 回答 1

-1

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

id=StringField(db_field="_id")

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

记录所有已解决的问题

于 2013-01-28T15:41:27.620 回答