Python rest_framework.mixins.CreateModelMixin() Examples
The following are 3
code examples of rest_framework.mixins.CreateModelMixin().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.mixins
, or try the search function
.
Example #1
Source File: views.py From CTF_AWD_Platform with MIT License | 6 votes |
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)
Example #2
Source File: views.py From CTF_AWD_Platform with MIT License | 6 votes |
def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) mobile = serializer.validated_data['mobile'] list = [] list.append(mobile) code = self.generate_code() SendCode.SendMail.delay(code, list) code_record = VerifyCode(code=code, mobile=mobile, type='email') code_record.save() return Response({ "mobile": mobile }, status=status.HTTP_201_CREATED) # class UserLogViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
Example #3
Source File: tests.py From product-definition-center with MIT License | 5 votes |
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')