Django REST Framework viewset actions

3924
0

Custom actions extend viewsets beyond CRUD operations. I use @action decorator with detail=True/False for object-level or collection-level actions. This creates endpoints like /posts/1/publish/ or /posts/recent/. I specify HTTP methods, permissions, and serializers per action. Actions keep related logic together in one viewset. For complex operations not fitting REST patterns, actions provide flexibility. I use URL name from action for reverse(). This extends APIs naturally without new viewsets.