2011-10-26 50 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()