本文整理匯總了Python中rest_framework.viewsets.ViewSet方法的典型用法代碼示例。如果您正苦於以下問題:Python viewsets.ViewSet方法的具體用法?Python viewsets.ViewSet怎麽用?Python viewsets.ViewSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rest_framework.viewsets
的用法示例。
在下文中一共展示了viewsets.ViewSet方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_action_methods_manager_mixin
# 需要導入模塊: from rest_framework import viewsets [as 別名]
# 或者: from rest_framework.viewsets import ViewSet [as 別名]
def test_action_methods_manager_mixin(self):
'''
Test if action methods specified on managers using action_methods
class field are registered with viewset
'''
class MockManager(SessionMixin, AlchemyModelManager):
model_class = mock.Mock()
action_methods = {'method_name': ['POST', 'DELETE']}
def method_name(self, data, pk=None, **kwargs):
return {'status': 'created'}
class MockViewSet(viewsets.ViewSet, ManagerMixin):
manager_class = MockManager
viewset = MockViewSet()
self.assertTrue(hasattr(viewset, 'method_name'))
method = getattr(viewset, 'method_name')
# DRF looks for methods with this attr
self.assertTrue(hasattr(method, 'bind_to_methods'))
示例2: get_queryset
# 需要導入模塊: from rest_framework import viewsets [as 別名]
# 或者: from rest_framework.viewsets import ViewSet [as 別名]
def get_queryset(self):
"""
Stub method because ViewSet requires one, even though we are not
retrieving querysets directly (we use the query in figures.sites)
"""
pass
示例3: create
# 需要導入模塊: from rest_framework import viewsets [as 別名]
# 或者: from rest_framework.viewsets import ViewSet [as 別名]
def create(self, request):
"""
Validate the given form input, and return any errors as json.
Not really a list view, but we have to use `list` to fit into ViewSet
semantics so this can be part of the browsable api.
"""
form = BetaTestApplicationForm(request.data,
instance=self.get_object())
return Response(form.errors)
示例4: get_permissions
# 需要導入模塊: from rest_framework import viewsets [as 別名]
# 或者: from rest_framework.viewsets import ViewSet [as 別名]
def get_permissions(self):
"""Define custom permissions for different methods"""
# at minimum require users to be authenticated
self.permission_classes = [IsAuthenticated]
# for PUT requests require users to be admins
if self.request.method == 'PUT':
self.permission_classes.append(IsAdminUser)
return super(viewsets.ViewSet, self).get_permissions()