GenericViewSet and Mixin

I don’t understand why it also have Mixin and GenericViewSet in the arguments ?

Is the GenericViewSet handled HTTP requests and is Mixin defined for CRUD operations with the database?

Do I understand that right?
image

You are basically right, the GenericViewSet acts as a container to allows us to combine multiple crud operations into one view. ie: before the create, get, update, delete http methods were in separate views now we can combine them all into one to reduce code duplication.

The Mixins seperately handle each http method. ie: CreateModelMixin for post, RetrieveModelMixin for get, DestroyModelMixin for Delete.

Note we could have just inherit from ModelViewSet inside the parethesis but this class provides all operations, but for carts we don’t need to list all carts in our database or update a cart.

1 Like