Combine Related Resources With TastyPie

Posted by Aaron Ng on Stack Overflow See other posts from Stack Overflow or by Aaron Ng
Published on 2012-09-15T09:01:16Z Indexed on 2012/09/15 9:37 UTC
Read the original article Hit count: 224

Filed under:
|
|

How can I combine multiple Resources in TastyPie? I have 3 models I'd like to combine: users, profiles and posts.

Ideally I'd like profiles nested within user. I'm not sure where to go from here.

class UserResource(ModelResource):

    class Meta:
        queryset = User.objects.all()
        resource_name = 'user'
        fields = ['username','id','date_joined']

        #Improper Auth
        authorization = Authorization()

class UserProfileResource(ModelResource):

    class Meta:
        queryset = UserProfile.objects.all()
        resource_name = 'profile'


class UserPostResource(ModelResource):
    user = fields.ForeignKey(UserResource,'user', full=True)


    class Meta:
        queryset = UserPost.objects.all()
        resource_name = 'userpost'

        #Improper Auth
        authorization = Authorization()

© Stack Overflow or respective owner

Related posts about python

Related posts about django