2011-10-26 86 views
0

我剛剛發現tastypie,我認爲它很棒。但我在按摩json的輸出時遇到了一些麻煩。tastypie脫水兒童資源字段

例如,我有這樣的事情:

... 

class UserResource(ModelResource): 
    class Meta: 
    queryset = User.objects.all() 


class Video(ModelResource): 
    favorites = fields.ManyToManyField(UserResource, 'favorites') 

    class Meta: 
    queryset = Video.objects.all() 

... 

其中最喜歡的是誰已收藏了視頻用戶的列表。我想輸出到看東西像JSON:

{ 
    "objects": 
    [{ 
     "title": "video title", 
     "favorites": 
     { 
     "count" : 3, 
     ["john", "bob", "carol"] 

     } 
    }] 
} 

回答

1

你可以嘗試以下?:

class Video(ModelResource): 
    favorites = fields.ManyToManyField(UserResource, 'favorites', full=True) 

    class Meta: 
    queryset = Project.objects.all()