假設我有一個資源像下面..如何僅返回tastypie中的一個字段?
class PostResource(ModelResource):
children = fields.ToManyField('MyApp.api.resources.PostResource',
attribute='comments', full=True, null=True)
基本上,我只想回到這個領域的兒童和平整。
它看起來像
[ {child-1-data}, {child-2-data} ]
而不是 { children: [ {child-1-data}, {child2-data} ] }
我怎麼能這樣做?
另外,如果我想要一個相同的模型類的不同表示,我應該創建一個新的資源類如下:
class PostNormalResource(ModelResource):
class Meta:
queryset= models.Post.objects.all()
fields = ['text', 'author']