class CreateModelMixin

from rest_framework.mixins import CreateModelMixin
Documentation Source code
    Create a model instance.
    

Ancestors (MRO)

  1. CreateModelMixin

Methods used but not implemented in this class

  • get_serializer
Expand Collapse

Methods

def create(self, request, *args, **kwargs): CreateModelMixin

    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

def get_success_headers(self, data): CreateModelMixin

    def get_success_headers(self, data):
        try:
            return {'Location': data[api_settings.URL_FIELD_NAME]}
        except (TypeError, KeyError):
            return {}

def perform_create(self, serializer): CreateModelMixin

    def perform_create(self, serializer):
        serializer.save()