0

I'm using Django-piston and I'd like to get user objects that include user profile data.

I'm trying :

class UserHandler(BaseHandler):
    model = User
    fields = ('id', 'username', 'favorite_color')

...

favorite_color is defined in UserProfile

The result is only printing id and username and nothing for favorite color.

9-bits
  • 10,395
  • 21
  • 61
  • 83
  • Are you sure favorite color value isn't empty? Just a guess - if favorite_color is defined in UserProfile (not on User model) you can't access it directly through User model. – WTK Jan 20 '12 at 06:57

2 Answers2

0

check if you already use model=User in other handler

and look at this https://bitbucket.org/jespern/django-piston/wiki/FAQ

LXG
  • 1,957
  • 3
  • 22
  • 45
0

If your UserProfile is linked to the User via a OneToOneField, you should be able to do it by walking the relation, using the nested-tuple syntax. (The following is untested)

class UserHandler(BaseHandler):
    model = User
    fields = ('id', 'username', ('userprofile', ('favorite_color',))

...

See the docs here

Steve Jalim
  • 11,989
  • 1
  • 37
  • 54