는 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']