5👍
✅
There is no standard but you can start with this simple strategy:
- Specific action on a model class — generic views (
RetrieveAPIView
,
ListAPIView
,UpdateAPIView
, etc.) - Several actions in one class and basic CRUD — ViewSets (
ModelViewSet
andReadOnlyModelViewSet
are most useful) - Some action on 1 instance — ViewSet +
@action(detail=True)
- Some action on several or all objects — ViewSet +
@action(detail=False)
- Simplest custom actions — function based views or
@action
again.
Also check DRF views classes for quick overview.
Source:stackexchange.com