0PricingLogin
Django Academy · Lesson

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 = BookSerializer

All lessons in this course

  1. ModelViewSet and Routers
  2. Permissions and Throttling
  3. Token and JWT Authentication
  4. Filtering, Search, and Pagination
← Back to Django Academy