[Answer]-Django tastypie reverse relation not working

0👍

CustomerProfile bind to User with one-to-one relationship, so you should to use fields.OneToOneField in UserResource:

class UserResource(ModelResource):                                                                  
    '''Fetch user details'''                                                                        
    custom_profile = fields.OneToOneField(CustomerProfileResource, 'custom_profile', related_name='profile', full=True)

    class Meta:
        fields = ['id', 'username', 'custom_profile']  # other fields what you need
        ...

1👍

Luckly I got the answer by hit and trial 🙂

As CustomerProfile resource is mapped to the UserResouce by OneToOne mapping so we have to use fields.ToOneField instead of fields.ToManyField while doing the reverse relation from UserResource as following :

profile = fields.ToOneField('coin.api.CustomerProfileResource', 'profile', null=True, full=True)

But still if somebody could able to clarify the resource mapping and reverse mapping clearly, that will be quite helpful for all, apparently django official documentation was not able to help me a lot.

Thanks

Leave a comment