Python rest_framework.mixins.UpdateModelMixin() Examples
The following are 2
code examples of rest_framework.mixins.UpdateModelMixin().
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: 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')
Example #2
Source File: mixins.py From resolwe with Apache License 2.0 | 4 votes |
def update(self, request, *args, **kwargs): """Update a resource.""" # NOTE: Use the original method instead when support for locking is added: # https://github.com/encode/django-rest-framework/issues/4675 # return super().update(request, *args, **kwargs) with transaction.atomic(): return self._update(request, *args, **kwargs) # NOTE: This is a copy of rest_framework.mixins.UpdateModelMixin.update(). # The self.get_object() was replaced with the # self.get_object_with_lock() to lock the object while updating. # Use the original method when suport for locking is added: # https://github.com/encode/django-rest-framework/issues/4675