'Nested routes with APIViews in Django Rest Framework

I'm writing my school project, building Django Rest API. And I have next entities: Profiles, Albums, Images, Comments, Likes.

What I'm trying is make resources accessible in this way: api/v1/profiles/1/albums --> get all the albums from profile with the id 1

On the examples, there is ViewSet used, instead APIView which I wanted to use ( I'm really newbie, and I don't even know can I use ViewSet for CRUID operations ). I've tried to implement the following:

and many others, but I can't get it working...

If there is some detailed tutorial, please reference it, I'd really need to be fast finishing this.

Thanks everybody!



Solution 1:[1]

may be you need extra-link-and-actions, for example:

from rest_framework.decorators import detail_route

class ProfileView
    # Your Code Here

    @detail_route(methods=['GET'])
    def albums(request, pk=None):
        # Heed to change related name 'albums_set'
        qs = self.get_object().albums_set.all()
        serializer = AlbumsSerializer(qs, many=True)
        return Response(serializer.data)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brown Bear