I´m building an API with Django Rest Framework, and I’m wondering if it's enough to use only the ModelViewSet class to implement the CRUD. My worries is that it’s not enough for the frontend to consume and use the create, read, update and delete functionalities.
CodePudding user response:
For a short answer, "yes".
But, I would suggest you to read the official docs from DRF.
ModelViewSet's docs
The
ModelViewSet
classinherits
fromGenericAPIView
and includes implementations for various actions, by mixing in the behavior of the various mixin classes.
The actions provided by the
ModelViewSet
class are .list(), .retrieve(), .create(), .update(), .partial_update(), and .destroy().
GenericAPIView's docs
This class
extends
REST framework'sAPIView
class, adding commonly required behavior for standard list and detail views.
Each of the
concrete generic views
provided is built by combiningGenericAPIView
, with one or moremixin
classes.
--
There are also plenty of blogs explaining why and when to use these class.
Django Rest Framework ViewSets
--
Lastly, I'm new to the community just like you did. I'm not sure this kind of question would be allowed here or not. But, what I'm trying to say is..
Stop worrying, just go and try out yourself. I believe that people in the community would willing to help you out if you've stuck.