Django REST Framework's ModelViewSet

Django REST Framework tip:

If your API endpoints map close to your models, you can save yourself quite a few lines of code by using ModelViewSet in combination with a router.

class PostModelViewSet(ModelViewSet):
    serializer_class = PostSerializer
    queryset = Post.objects.all()

router = routers.DefaultRouter()
router.register(r'', PostModelViewSet)

urlpatterns = [
    path('', include(router.urls)),

# yields:      # for list of posts  # for post detail

(ViewSets should be stored in a file named rather than