Friday, 13 May 2022

django ModelViewSet in views , model mixins, and serializers

 https://www.django-rest-framework.org/api-guide/generic-views/#createapiview

https://stackoverflow.com/questions/37537974/django-rest-framework-serializers-and-views

CreateAPIView

Used for create-only endpoints.

Provides a post method handler.

Extends: GenericAPIViewCreateModelMixin


perform_create(self, serializer) - Called by CreateModelMixin when saving a new object instance.

perform_update(self, serializer) - Called by UpdateModelMixin when saving an existing object instance.

perform_destroy(self, instance) - Called by DestroyModelMixin when deleting an object instance.



  • mixins.CreateModelMixin - calling validate & create -> serializer.save -> serializer.create
  • mixins.RetrieveModelMixin - "get" instance
  • mixins.UpdateModelMixin - calling validate & update/partial update -> serializer.save -> serializer.update
  • mixins.DestroyModelMixin - calling instance delete
  • mixins.ListModelMixin - "get" list of instances (browse)

No comments:

Post a Comment