我无法弄清楚为什么我的 UserResource 总是为每个对象显示 null,即使 verify_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}]