当前位置: 首页>>代码示例>>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;未经允许,请勿转载。