Skip to content

Instantly share code, notes, and snippets.

@Joel-hanson
Created June 3, 2019 04:16
Show Gist options
  • Save Joel-hanson/6cbbf56b3de6afa75f6b2c1f45f6a5ee to your computer and use it in GitHub Desktop.
Save Joel-hanson/6cbbf56b3de6afa75f6b2c1f45f6a5ee to your computer and use it in GitHub Desktop.
We will be using the ModelViewSet and ModelSerializer to make the API for our Book model.
from rest_framework.viewsets import ModelViewSet
from rest_framework.authentication import SessionAuthentication
from .serializers import BookModelSerializer
from .models import Book
# Create your views here.
class BookModelViewSet(ModelViewSet):
"""
A simple ViewSet for viewing and editing books.
"""
queryset = Book.objects.all()
serializer_class = BookModelSerializer
authentication_classes = [SessionAuthentication]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment