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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:57:34+00:00 2026-06-11T03:57:34+00:00

I have a problem with tastypie regarding updates to two models with one (POST)

  • 0

I have a problem with tastypie regarding updates to two models with one (POST) api call.

We have two models, an user model and a candidate model which references the user model. We want to publish the candidate model via the api interface, but want to hide the user model. So, as a first step I merge the user model fields with the candidate model fields in the dehydrate process. This is working completly fine.

The problem is, that I can’t figure out, how to do it the other way round (hydrate and create both models. we need to create a seperate user model and cant just merge both models)

  • 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-11T03:57:35+00:00Added an answer on June 11, 2026 at 3:57 am

    Would be nice if you showed us some code and what have you tried, but for this kind of task you should probably override the obj_create(...) method of tastypie.resources.ModelResource class.

    It looks like this:

        def obj_create(self, bundle, request=None, **kwargs):
            """
            A ORM-specific implementation of ``obj_create``.
            """
            bundle.obj = self._meta.object_class()
    
            for key, value in kwargs.items():
                setattr(bundle.obj, key, value)
    
            bundle = self.full_hydrate(bundle)
    
            # Save FKs just in case.
            self.save_related(bundle)
    
            # Save the main object.
            bundle.obj.save()
    
            # Now pick up the M2M bits.
            m2m_bundle = self.hydrate_m2m(bundle)
            self.save_m2m(m2m_bundle)
            return bundle
    

    So in your resource you could have something like:

    from tastypie.resources import ModelResource
    
    class MyResource( ModelResource ):
    
        def obj_create( self, bundle, request = None, **kwargs ):
            # ...
            # create User instance based on what's in the bundle
            # user = ...
            # ...
            # kwargs[ 'user' ] = user < will be set on Candidate instance in super()
            # ...
    
            # call super, resulting in creation of the Candidate model
            super( MyResource, self ).obj_create( self, bundle, request, **kwargs )
    

    And this should get you started. If you have any trouble, please ask a question and provide some code.

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

Sidebar

Related Questions

I'm building a simple API using django-tastypie. The idea is I have two resources:
I have problem with the CSS. I'm changing dynamically one div's content. The problem
i have problem with jquery submit and post. I would like to submit a
i have problem i can't solve for a while. For one of my C++
I have a problem with a Tastypie/Django JSON response in my Java Android code.
I have problem with one of my validation regex when using nonstandard utf-8 character.
I have problem on deleting component which is created on runtime. Please help me.
I have problem with loading my jqGrid. It just loads two parallel lines, and
I'm trying to go with-the-grain using Django TastyPie to update my models. I have
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar

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.