我有两个资源:UserResource和ChannelResource,如下:
class ChannelResource(ModelResource):
class Meta:
queryset = Channel.objects.all()
resource_name = 'channels'
class UserResource(ModelResource):
channels = fields.ToManyField(ChannelResource, 'channels', full=True)
stories = fields.ToManyField('core.api.StoryResource', 'stories', full=True)
class Meta:
queryset = User.objects.all()
resource_name = 'users'
我可以获取有关单个用户的用户列表和信息(包括他拥有的频道):
http://localhost/api/users/1/?format=json&limit=0
{
channels: [
{
id: 1,
identifier: "default",
name: "default",
resource_uri: "/api/v1/channels/1/"
}],
id: 1,
name: threejeez
}
但是当我尝试为用户获取频道列表时,出现错误:
http://localhost/api/users/1/channels/?format=json&limit=0
error_message: "Invalid resource lookup data provided (mismatched type)."
我可以从上面的 json 中看到资源位于 api/channels/,但我希望它位于 api/users/1/channels。我怎样才能做到这一点?
谢谢!