當前位置: 首頁>>代碼示例>>Python>>正文


Python mixins.CreateModelMixin方法代碼示例

本文整理匯總了Python中rest_framework.mixins.CreateModelMixin方法的典型用法代碼示例。如果您正苦於以下問題:Python mixins.CreateModelMixin方法的具體用法?Python mixins.CreateModelMixin怎麽用?Python mixins.CreateModelMixin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.mixins的用法示例。


在下文中一共展示了mixins.CreateModelMixin方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

# 需要導入模塊: from rest_framework import mixins [as 別名]
# 或者: from rest_framework.mixins import CreateModelMixin [as 別名]
def create(self, request, *args, **kwargs):
        '''
        對CreateModelMixin 中的create方法進行重寫,發送驗證碼並保存到數據庫中
        :param request:
        :param args:
        :param kwargs:
        :return:
        '''
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        mobile = serializer.validated_data["mobile"]

        code = self.generate_code()
        data = [code, '5']  # 驗證碼在五分鍾後失效

        SendCode.SendSMS.delay(to=mobile, data=data, tempId=1)

        code_record = VerifyCode(code=code, mobile=mobile, type='mobile')
        code_record.save()
        return Response({
            "mobile": mobile
        }, status=status.HTTP_201_CREATED) 
開發者ID:xuchaoa,項目名稱:CTF_AWD_Platform,代碼行數:25,代碼來源:views.py

示例2: setUp

# 需要導入模塊: from rest_framework import mixins [as 別名]
# 或者: from rest_framework.mixins import CreateModelMixin [as 別名]
def setUp(self):

        class DummySerializer(serializers.Serializer):
            nickname = serializers.CharField()
            color = serializers.CharField()

            def create(self, validated_data):
                return mock.Mock(pk=2, **validated_data)

            def update(self, obj, validated_data):
                return mock.Mock(pk=obj.pk, **validated_data)

        class GetDogMixin(object):
            def get_object(self):
                return mock.Mock(pk=1, nickname='Spot', color='black')

        class DummyView(viewsets.NotificationMixin,
                        mixins.CreateModelMixin,
                        mixins.UpdateModelMixin,
                        mixins.DestroyModelMixin,
                        GetDogMixin,
                        GenericViewSet):
            serializer_class = DummySerializer

        mapping = {
            'post': 'create',
            'put': 'update',
            'delete': 'destroy',
        }
        self.view = DummyView.as_view(mapping, basename='dummy') 
開發者ID:product-definition-center,項目名稱:product-definition-center,代碼行數:32,代碼來源:tests.py


注:本文中的rest_framework.mixins.CreateModelMixin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。