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 8846687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:03:45+00:00 2026-06-14T12:03:45+00:00

I am starting to add Tastypie to a very small Django application I’m developing,

  • 0

I am starting to add Tastypie to a very small Django application I’m developing, and I was wondering if there is a way to send just the numeric id of a resource pointed to by a relationship, instead of the uri where the resource resides.

For instance, using one of the examples provided in the documentation:

The exposed “Entry” resource looks like:

{
    "body": "Welcome to my blog!",
    "id": "1",
    "pub_date": "2011-05-20T00:46:38",
    "resource_uri": "/api/v1/entry/1/",
    "slug": "first-post",
    "title": "First Post",
    "user": "/api/v1/user/1/"
}

It has a relationship towards “user” that shows as "user": "/api/v1/user/1/". Is there any way of just making it "user": 1 (integer, if possible) so it looks like the following?

{
    "body": "Welcome to my blog!",
    "id": "1",
    "pub_date": "2011-05-20T00:46:38",
    "resource_uri": "/api/v1/entry/1/",
    "slug": "first-post",
    "title": "First Post",
    "user": 1
}

I like the idea or keeping the resource_uri attribute as whole, but when it comes to modeling Sql Relationships, I’d rather have just the id (or a list of numeric ids, if the relationship is “ToMany“). Would it be good idea adding a dehydrate_user method to the EntryResource class to do this? It seems to work, but maybe there’s a more generic way of doing it (to avoid having to write a dehydrate method for every relationship)

Thank you in advance

  • 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-14T12:03:46+00:00Added an answer on June 14, 2026 at 12:03 pm

    You can try using hydrate dehydrate cycles

    def dehydrate(self, bundle):
        bundle.data['entry'] = bundle.obj.entry.id
        return bundle
    
    def hydrate(self, bundle):
        bundle.data['entry'] = Entry.objects.get(id=bundle.data['entry'])
        return bundle
    

    BUT I strongly recommend to stick with URI usage since it is how you can adress directly a resource. Hydrate and dehydrate are used for more complexe or virtual resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just starting to poke around iPhone development. I am trying to add an external
I'm just starting out writing this code and when I add in the db
I'm starting to use MVVM,but I've been confused about something,there's my problem,I wanna add
I've recently starting developing with the android sdk. Currently, I am trying to add
I've been developing a simple website using asp.net MVC and I'm starting to add
I am just starting with Excel 2010 Add-in with VSTO and is quickly stumped
I'm starting developing app in WindowsPhone, and had some problems. I trying to add
I'm starting to add some Groovy classes to an existing Java web app. (This
I'm starting to learn Backbone with this simple example: <div id=counter>unkown</div> <button id=add-button>ADD</button> (function($){
Starting with API level 9, there's android:filterTouchesWhenObscured attribute and corresponding setFilterTouchesWhenObscured method on ViewGroup

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.