Reputation: 3314
I am using django tastypie and I'm trying to add a nested userprofile resource in my user resources:
My code:
Models (in APP_FOLDER/models.py):
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='userprofile')
Resource definitions (in API/resources.py):
class UserResource(ModelResource):
userprofile = fields.ToManyField('api.resources.UserProfileResource', 'userprofile', full=True)
class Meta:
queryset = User.objects.all()
resource_name = 'user'
class UserProfileResource(ModelResource):
user = fields.ToOneField(UserResource,'user')
class Meta:
queryset = UserProfile.objects.all()
resource_name = 'userprofile'
When I try to access the users I get: error_message: "'UserProfile' object has no attribute 'all'". Am I missing something?
Upvotes: 1
Views: 1513
Reputation: 3314
I figured it out: I needed to change fields.ToManyField to fields.ToOneField in the UserResource since the relationship is one to one in the models.
Upvotes: 1