Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I assume you're using Django 1.4 and <a href="https://docs.djangoproject.com/en/1.4/topics/auth/#storing-additional-information-about-users" rel="nofollow"><code>AUTH_PROFILE_MODULE</code></a>?</p> <p>Since the User:UserProfile relationship is 1:1 I would opt for the <a href="https://django-tastypie.readthedocs.org/en/latest/fields.html#toonefield" rel="nofollow">ToOneField</a> instead. This will serialize as a URI pointer to your UserProfileResource (if one exists.) If you'd like the UserProfileResource field data inline with your UserResource, you can specify <a href="https://django-tastypie.readthedocs.org/en/latest/fields.html#full" rel="nofollow"><code>full=True</code></a> in the ToOneField definition. With this method you should not need to override dehydrate.</p> <p>Also, ensure that the second argument in the ToOneField definition is the User attribute which points to your UserProfile Django model. For example if you have <code>OneToOneField(User, related_name='profile')</code> in your Django model then this attribute should be <code>profile</code>.</p> <pre><code>class UserResource(ModelResource): profile = fields.ToOneField('foo.api.UserProfileResource', 'profile', full=True, null=True) class Meta: queryset = User.objects.all() resource_name = 'users' allowed_methods = ['get'] </code></pre> <hr> <p>If what you're after are specific fields from the UserProfile instance mixed in with your User, you should be able to do something like this:</p> <pre><code>class UserResource(ModelResource): date_of_birth = fields.DateField('profile__date_of_birth', null=True) class Meta: queryset = User.objects.all() resource_name = 'users' allowed_methods = ['get'] fields = ['userfields', 'gohere', 'date_of_birth'] </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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