ModelViewSet and Routers
Generate CRUD routes automatically.
The CRUD Repetition Problem
Writing list, create, retrieve, update, and delete by hand means a lot of near-identical code. A ViewSet bundles all of it into one tidy class.
Meet ModelViewSet
The ModelViewSet gives you full CRUD for a model with almost no code. Point it at a queryset and a serializer, and it handles the rest.
from rest_framework import viewsets
class BookViewSet(viewsets.ModelViewSet):
queryset = Book.objects.all()
serializer_class = BookSerializerAll lessons in this course
- ModelViewSet and Routers
- Permissions and Throttling
- Token and JWT Authentication
- Filtering, Search, and Pagination