Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango TastyPie PUT Nested User Model Correctly
    primarykey
    data
    text
    <p>I'm trying to go with-the-grain using Django TastyPie to update my models. I have an Identity model, acting as a wrapper around default Django user model:</p> <pre><code>class Identity(ProfileBase): user = models.OneToOneField(User, related_name='identity') avatar = models.ImageField(upload_to=avatar_upload_path, blank=True, null=True) </code></pre> <p>I have my <code>UserResource</code>:</p> <pre><code>class UserResource(ModelResource): class Meta: resource_name = 'user' queryset = User.objects.all() fields = ['email', 'first_name', 'last_name'] include_resource_uri = False </code></pre> <p>And I have my <code>IdentityResource</code>:</p> <pre><code>class IdentityResource(ModelResource): user = fields.ToOneField(UserResource, 'user', full=True) class Meta: resource_name = 'identity' queryset = Identity.objects.select_related() fields = ['user', 'avatar'] always_return_data = True include_resource_uri = False authentication = OAuthTokenAuthentication() authorization = Authorization() </code></pre> <p>I'm currently successfully updating first_name, last_name using the ModelResource <code>obj_update</code> method within <code>IdentityResource</code>:</p> <pre><code>def obj_update(self, bundle, request, **kwargs): print 'updating object' bundle = self.full_hydrate(bundle) bundle.obj.user = request.user user = bundle.data['user'] bundle.obj.user.first_name = user['first_name'] bundle.obj.user.last_name = user['last_name'] return super(IdentityResource, self).obj_update(bundle, request, user=request.user) </code></pre> <p><strong>I want to make a <code>PUT</code> request and optionally update any field on the user or identity models (first_name, last_name on user, or the avatar field on identity).</strong> I would rather not have to manually access each field from the bundle data and set them on models manually, as I have done above. </p> <p>How can I do this naturally in TastyPie? Can someone explain a better approach to solving this problem? Any direction is GREATLY appreciated. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload