當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。