0
0
Djangoframework~10 mins

Generic views in DRF in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the generic ListAPIView from Django REST Framework.

Django
from rest_framework import [1]
Drag options to blanks, or click blank then click option'
Aserializers
Bviews
Cpermissions
Dgenerics
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from rest_framework.views instead of rest_framework.generics
Trying to import ListAPIView directly from rest_framework
2fill in blank
medium

Complete the code to create a ListAPIView for a model named Book.

Django
class BookListView([1]):
    queryset = Book.objects.all()
    serializer_class = BookSerializer
Drag options to blanks, or click blank then click option'
AAPIView
BListAPIView
CGenericAPIView
DModelViewSet
Attempts:
3 left
💡 Hint
Common Mistakes
Using APIView which requires manual method definitions
Using ModelViewSet which is for full CRUD, not just listing
3fill in blank
hard

Fix the error in the code by completing the missing generic view class to retrieve and update a single Book instance.

Django
class BookDetailView([1]):
    queryset = Book.objects.all()
    serializer_class = BookSerializer
Drag options to blanks, or click blank then click option'
ARetrieveUpdateAPIView
BRetrieveAPIView
CRetrieveDestroyAPIView
Attempts:
3 left
💡 Hint
Common Mistakes
Using RetrieveAPIView which only supports GET
Using RetrieveDestroyAPIView which supports retrieve and destroy instead of update
4fill in blank
hard

Fill both blanks to create a generic view that supports listing and creating Book objects.

Django
class BookListCreateView([1], [2], GenericAPIView):
    queryset = Book.objects.all()
    serializer_class = BookSerializer
Drag options to blanks, or click blank then click option'
AListModelMixin
BCreateModelMixin
CGenericAPIView
DAPIView
Attempts:
3 left
💡 Hint
Common Mistakes
Using APIView directly without mixins
Using GenericAPIView alone without mixins
5fill in blank
hard

Fill all three blanks to define a generic view that supports retrieve, update, and destroy actions for Book.

Django
class BookDetailView([1], [2], [3], GenericAPIView):
    queryset = Book.objects.all()
    serializer_class = BookSerializer
Drag options to blanks, or click blank then click option'
ARetrieveModelMixin
BUpdateModelMixin
CDestroyModelMixin
DListModelMixin
Attempts:
3 left
💡 Hint
Common Mistakes
Including ListModelMixin which is for listing multiple objects
Missing one of the required mixins