Python tastypie api未在json结果中显示ForeignKey
我最近开始使用tastypie为一个潜在的智能手机应用程序打开api 我正在使用python-2.7和Django-1.1.2 有两件事让我困惑 1:在Python tastypie api未在json结果中显示ForeignKey,python,django,json,api,Python,Django,Json,Api,我最近开始使用tastypie为一个潜在的智能手机应用程序打开api 我正在使用python-2.7和Django-1.1.2 有两件事让我困惑 1:在EntryResource类中,当调用ForeignKey时,他们只调用资源和资源名称,当我以这种方式执行时,我得到以下回溯 691. assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ForeignKey must be either a mode
EntryResource
类中,当调用ForeignKey
时,他们只调用资源和资源名称,当我以这种方式执行时,我得到以下回溯
691. assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
Exception Type: AssertionError at /api/v1/activity-stream-item-subject/
Exception Value: ForeignKey(<class 'api.resources.UserResource'>) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
有什么想法吗?我不确定是否理解您的第一个问题,但关于第二个问题,您需要使用以下方法指定您想要的完整资源:
user = fields.ForeignKey(UserResource, 'user',full=True)
否则,您将获得资源URI而不是内容。()
同样仅供参考,请记住,要求中说明:
Django 1.2+(可能适用于Django 1.1)
如果要在json结果中显示用户的所有字段,必须设置
full=True
user = fields.ForeignKey(UserResource,user,full=True)
true是无效的
user = fields.ForeignKey(UserResource,user,full=True)