当前位置: 首页>>代码示例>>Python>>正文


Python viewsets.ViewSet方法代码示例

本文整理汇总了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')) 
开发者ID:dealertrack,项目名称:djangorest-alchemy,代码行数:24,代码来源:test_viewsets.py

示例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 
开发者ID:appsembler,项目名称:figures,代码行数:8,代码来源:views.py

示例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) 
开发者ID:open-craft,项目名称:opencraft,代码行数:12,代码来源:views.py

示例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() 
开发者ID:BrewCenter,项目名称:BrewCenterAPI,代码行数:12,代码来源:fermentables.py


注:本文中的rest_framework.viewsets.ViewSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。