本文整理汇总了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()