本文整理汇总了Python中rest_framework.mixins.ListModelMixin方法的典型用法代码示例。如果您正苦于以下问题:Python mixins.ListModelMixin方法的具体用法?Python mixins.ListModelMixin怎么用?Python mixins.ListModelMixin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.mixins
的用法示例。
在下文中一共展示了mixins.ListModelMixin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from rest_framework import mixins [as 别名]
# 或者: from rest_framework.mixins import ListModelMixin [as 别名]
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
mobile = serializer.validated_data['mobile']
list = []
list.append(mobile)
code = self.generate_code()
SendCode.SendMail.delay(code, list)
code_record = VerifyCode(code=code, mobile=mobile, type='email')
code_record.save()
return Response({
"mobile": mobile
}, status=status.HTTP_201_CREATED)
# class UserLogViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
示例2: add_viewset
# 需要导入模块: from rest_framework import mixins [as 别名]
# 或者: from rest_framework.mixins import ListModelMixin [as 别名]
def add_viewset(table):
data_index = table.name
record_data_index = "{}.".format(table.name)
deleted_data_index = "{}..".format(table.name)
def list(self, request, *args, **kwargs):
page = int(request.query_params.get("page", 1))
page_size = int(request.query_params.get("page_size", 10))
try:
res = es.search(index=deleted_data_index, doc_type="deleted-data", size=page_size, from_=(page-1)*page_size)
except Exception as exc:
raise exceptions.APIException("内部错误,错误类型: {}".format(type(exc)))
return Response(res["hits"])
def retrieve(self, request, *args, **kwargs):
try:
res = es.get(index=deleted_data_index, doc_type="data", id=kwargs["pk"])
except NotFoundError as exc:
raise exceptions.NotFound("Document {} was not found in Type {} of Index {}".format(kwargs["pk"], "data", table.name))
viewset = type(table.name, (mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet),
dict(permission_classes=(c_permissions.TableLevelPermission, ), list=list, retrieve=retrieve))
setattr(views, table.name, viewset)
return viewset
示例3: test_001_default_order
# 需要导入模块: from rest_framework import mixins [as 别名]
# 或者: from rest_framework.mixins import ListModelMixin [as 别名]
def test_001_default_order(self):
# Ordering must be set to prevent:
# /usr/share/python/scirius-pro/local/lib/python2.7/site-packages/rest_framework/pagination.py:208: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'rules.models.RuleTransformation'> QuerySet
for url, viewset, view_name in self.router.registry:
# Need to instanciate request and user because of FilterSetViewSet::get_queryset override that uses self.request.user
v = viewset()
v.request = HttpRequest()
v.request.user = None
if v.get_queryset().ordered or not issubclass(viewset, mixins.ListModelMixin):
continue
ERR = 'Viewset "%s" must set an "ordering" attribute or have an ordered queryset' % viewset.__name__
self.assertTrue(hasattr(viewset, 'ordering'), ERR)
self.assertNotEqual(len(viewset.ordering), 0, ERR)
示例4: test_002_list
# 需要导入模块: from rest_framework import mixins [as 别名]
# 或者: from rest_framework.mixins import ListModelMixin [as 别名]
def test_002_list(self):
for url, viewset, view_name in self.router.registry:
if issubclass(viewset, mixins.ListModelMixin):
self.http_get(reverse(view_name + '-list'))