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

  • Home
  • SEARCH
  • 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 7067135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:09:53+00:00 2026-05-28T05:09:53+00:00

Im playing a little bit with heavy-client app. Imagine I have this model: class

  • 0

Im playing a little bit with heavy-client app.

Imagine I have this model:

class Category(models.Model):
    name = models.CharField(max_length=30)
    color = models.CharField(max_length=9)

Im using knockoutjs (but I guess this is not important). I have a list (observableArray) with categories and I want to create a new category.

I create a new object and I push it to the list. So far so good.

What about saving it on my db? Because I’m using tastypie I can make a POST to ‘/api/v1/category/’ and voilà, the new category is on the DB.

Ok, but… I haven’t refresh the page, so… if I want to update the new category, how I do it?

I mean, when I retrieve the categories, I can save the ID so I can make a put to ‘/api/v1/category/id’ and save the changes, but… when I create a new category, the DB assign a id to it, but my javascript doesn’t know that id yet.

in other words, the workflow is something like:

make a get > push the existing objects (with their ids) on a list > create a new category > push it on the list > save the existing category (the category doesnt have the id on the javacript) > edit the category > How I save the changes?

So, my question is, what’s the common path? I thought about sending the category and retrieving the id somehow and assign it to my object on js to be able to modify it later. The problem is that making a POST to the server doesn’t return anything.

In the past I did something like that, send the object via post, save it, retrieve it and send it back, on the success method retrieve the id and assign it to the js object.

Thanks!

  • 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-05-28T05:09:53+00:00Added an answer on May 28, 2026 at 5:09 am

    Tastypie comes with an always_return_data option for Resources.

    When always_return_data=True for your Resource, the API always returns the full object event on POST/PUT, so that when you create a new object you can get the created ID on the same request.

    You can then just read the response from your AJAX and decode the JSON (i dont know about knockout yet).

    see the doc : http://readthedocs.org/docs/django-tastypie/en/latest/resources.html?highlight=always_return_data#always-return-data

    Hope this helps

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

Sidebar

Related Questions

I'm playing with Hibernate a little bit. I created a Group class and a
I've been playing around with Direct3D 11 a little bit lately and have been
Background: I have a little video playing app with a UI inspired by the
Earlier it was working fine. I have been playing little bit config. So may
currently I'm playing a little bit with spine.js I have red the documentation about
I have been playing around with SQLite a little bit and I was looking
This surprised me a little bit, but I was playing around with some code
Playing a little with coffeescript and Rails 3.1.0.rc4. Have this code: yourMom = (location)
I'm playing a little bit with the new StackOverflow API . Unfortunately, my JSON
I'm playing around with list comprehensions and I came across this little snippet on

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.