'use of mixins class defined in Django rest framework
What is the actual use of Mixins class? I don't really get it. All the mixins classes like CreateModelmixin, Listmixin, etc features are already available in class-based view like ListCreateApiView.
For eg:
class ExampleView(ListCreateAPIView
DestroyAPIView,
RetrieveUpdateAPIView):
queryset = Example.objects.all()
serializer_class = ExampleSerializer
pagination_class = CustomPageNumberPagination
Using mixins we can do it by following:
class ExampleView(ListAPIView,
mixins.CreateModelMixin):
queryset = Example.objects.all()
serializer_class = ExampleSerializer
pagination_class = CustomPageNumberPagination
When I check https://www.cdrf.co/ I see the methods that are available in CreateModelMixing are the following:
def create(self, request, *args, **kwargs):
def get_success_headers(self, data):
def perform_create(self, serializer):
These methods are already available in ListCreateApiView, then why Django went to create this useless class??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
