django-tastypie用户资源始终为null

时间:2013-05-10 11:28:49

标签: django api django-models tastypie

我无法弄清楚为什么我的UserResource总是为每个对象显示null,即使在Observation_by_id正确地位于Observation模型的数据库中。

相关代码:

模型

class Observation(ProjModel):
    verified_by = models.ForeignKey(User, null=True)

    class Meta():
        app_label = 'observation'

资源

class ObservationResource(ProjResource):
    verified_by = fields.ForeignKey(UserResource, 'user', full=True, null=True)

    class Meta:
        queryset = Observation.objects.all()
        authentication = SessionAuthentication()
        authorization = DjangoAuthorization()
        resource_name = 'observation'

class UserResource(ProjResource):
    class Meta:
        queryset = User.objects.all()
        authentication = SessionAuthentication()
        authorization = DjangoAuthorization()
        resource_name = 'user'

JSON

"objects": [{"verified_by": null}]

1 个答案:

答案 0 :(得分:1)

您需要确保所有引用的Resources都在您的网址结构中,以便它们出现。