title: TastyPie: Consulting and updating fields from other models within a resource
body: <p>I have a Profile model with a OneToOne relationship with a User. For such Profile model I use the following class, which uses two additional fields coming directly from the User:</p>
  
  <pre><code>class ProfileResource(ModelResource):
      username = fields.CharField(attribute='user__username')
      email = fields.CharField(attribute='user__email')
  
      class Meta:
          # Base data
          queryset = Profile.objects.all()
  
          # Allowed methods
          list_allowed_methods = ['get']
          detail_allowed_methods = ['get', 'put', 'patch']
  
          # Security setup (FEEBLE)
          authorization = Authorization()
          authentication = BasicAuthentication()
  </code></pre>
  
  <p>Such resource works fine when consulting profiles. It retrieves the username and email perfectly, and is capable of filtering and ordering by such parameters.
  However, I cannot manage to update such fields on the User model in a, say, elegant fashion. All I have come up with is this:</p>
  
  <pre><code>    def obj_update(self, bundle, skip_errors=False, **kwargs):
          bundle = super().obj_update(bundle, skip_errors=skip_errors, **kwargs)
          if 'username' in bundle.data: bundle.obj.user.username = bundle.data['username']
          if 'email' in bundle.data: bundle.obj.user.email = bundle.data['email']
          bundle.obj.user.save()
          return bundle
  </code></pre>
  
  <p>Which works fine but doesn't seem the best of solutions.</p>
  
  <p>Does anybody know a better way to work out this kind of field-only relationship between a resource and a related model?</p>