Can @link be routed without a PC in the Django Rest Framework?

I would like to link "/ tags / browse" in the view, but I think the decorator forces "/ tags /: id / browse". Here is my view:

class TagViewSet(viewsets.ModelViewSet):
    queryset = Tag.objects.all()
    serializer_class = TagSerializer

    @link(permission_classes=[])
    def browse(self, request, pk=None):
        ...
        return Response(data)

I would like to have a common CRUD API for tags, but I also add a special view that returns some aggregated data. The current @link works, but I have to go to "/ tags / 1 / browse" instead of the general "/ tags / browse". Is there an easy way to do the latter here?

(I can make a separate route, but, if possible, prefer that everything is encapsulated in this view)

Thank!

+4
source share
1 answer

2014 , , 2.4. ...

https://github.com/tomchristie/django-rest-framework/pull/886
https://github.com/tomchristie/django-rest-framework/pull/1047

, - , PR ( 2.4, PyPI)

+2

Source: https://habr.com/ru/post/1544970/


All Articles