Bird
0
0

You want to create a DRF API that allows users to list and create 'Task' objects but restrict update and delete. Which DRF class should you use?

hard📝 Application Q8 of 15
Django - REST Framework Basics
You want to create a DRF API that allows users to list and create 'Task' objects but restrict update and delete. Which DRF class should you use?
Aviewsets.ModelViewSet
Bviewsets.ReadOnlyModelViewSet
CAPIView
Dmixins.ListModelMixin + mixins.CreateModelMixin + GenericViewSet
Step-by-Step Solution
Solution:
  1. Step 1: Understand required API actions

    Need list and create only, no update/delete.
  2. Step 2: Match DRF classes to actions

    Mixins ListModelMixin and CreateModelMixin combined with GenericViewSet provide only those actions.
  3. Step 3: Evaluate other options

    ModelViewSet includes all CRUD; ReadOnlyModelViewSet excludes create; APIView requires manual methods.
  4. Final Answer:

    mixins.ListModelMixin + mixins.CreateModelMixin + GenericViewSet -> Option D
  5. Quick Check:

    Selective actions = Mixins + GenericViewSet [OK]
Quick Trick: Use mixins to limit allowed actions in DRF [OK]
Common Mistakes:
MISTAKES
  • Using ModelViewSet without restricting actions
  • Choosing ReadOnlyModelViewSet which disallows create
  • Overcomplicating with APIView

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes