Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:15:51+00:00 2026-06-11T11:15:51+00:00

How can I combine multiple Resources in TastyPie? I have 3 models I’d like

  • 0

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’d like to expose both the user and all of the profile location from UserPostResource. 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()

Here are my models:

class UserProfile(models.Model):

    user = models.OneToOneField(User)

    website = models.CharField(max_length=50)
    description = models.CharField(max_length=255)
    full_name = models.CharField(max_length=50)


class UserPost(models.Model):
    user = models.ForeignKey(User)

    datetime = models.DateTimeField(auto_now_add=True)
    text = models.CharField(max_length=255, blank=True)
    location =  models.CharField(max_length=255, blank= True)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:15:52+00:00Added an answer on June 11, 2026 at 11:15 am

    Tastypie fields (when the resource is a ModelResource) allow passing in the attribute kwarg, which in turn accepts regular django nested lookup syntax.

    So, first of all this might be useful:

    # in UserProfile model (adding related_name)
    user = models.OneToOneField(User, related_name="profile")
    

    and given the above change, the following:

    from tastypie import fields
    
    class UserResource(ModelResource):
        # ... 
        website = fields.CharField(attribute = 'profile__website' )
        description = fields.CharField(attribute = 'profile__description' )
        full_name = fields.CharField(attribute = 'profile__full_name' )
        # ...
    

    will expose the data from UserProfile model within the UserResource.

    Now if you’d like to expose a list of locations (coming from UserPost) within the UserResource you will have to override one of Tastypie methods. According to the documentation a good candidate would be the dehydrate() method.

    Something like this should work:

    # in UserPost model (adding related_name)
    user = models.ForeignKey(User, related_name="posts")
    
    class UserResource(ModelResource):
        # ....
        def dehydrate(self, bundle):
            posts = bundle.obj.posts.all()
            bundle.data['locations'] = [post.location for post in posts]
            return bundle
        # ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How I can combine multiple form elements to one validator? I have address information
Currently I have multiple resources in a project that can only be accessed from
In Sass we can combine multiple partials into single css output like @import scss/header;
Is there any way I can combine list of expressions into one? I have
How can you combine two windows in Screen? I have two windows such that
How can I combine multiple NSArrays into one array with alternating values? For example.
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Is there a way I can combine the multiple WHERE's into one Here is
It is tag input box validation.A poster can combine multiple words into single-words, space
How can I combine multiple images, such as base image with logo and number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.