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


Python serializers.UUIDField方法代码示例

本文整理汇总了Python中rest_framework.serializers.UUIDField方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.UUIDField方法的具体用法?Python serializers.UUIDField怎么用?Python serializers.UUIDField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.serializers的用法示例。


在下文中一共展示了serializers.UUIDField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_object

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import UUIDField [as 别名]
def get_object(self):
        queryset = self.get_queryset()
        queryset = self.filter_queryset(queryset)
        pk = self.kwargs.get("pk")
        try:
            uuid = UUIDField().to_internal_value(data=pk)
            obj = Sources.objects.get(source_uuid=uuid)
            if obj:
                return obj
        except (ValidationError, Sources.DoesNotExist):
            pass

        try:
            int(pk)
            obj = get_object_or_404(queryset, **{"pk": pk})
            self.check_object_permissions(self.request, obj)
        except ValueError:
            raise Http404

        return obj 
开发者ID:project-koku,项目名称:koku,代码行数:22,代码来源:view.py

示例2: test_should_uuid_convert_string

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import UUIDField [as 别名]
def test_should_uuid_convert_string():
    if hasattr(serializers, "UUIDField"):
        assert_conversion(serializers.UUIDField, graphene.String) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:5,代码来源:test_field_converter.py

示例3: make_string_validator

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import UUIDField [as 别名]
def make_string_validator(cls, settings: ParamSettings):
        if settings.regex:
            return serializers.RegexField(
                settings.regex,
                default=settings.default,
                max_length=settings.max_length,
                min_length=settings.min_length,
            )

        if settings.format is None:
            return serializers.CharField(
                default=settings.default,
                max_length=settings.max_length,
                min_length=settings.min_length,
                trim_whitespace=settings.trim_whitespace,
            )

        if settings.format == "email":
            return serializers.EmailField(
                default=settings.default,
                max_length=settings.max_length,
                min_length=settings.min_length,
            )

        if settings.format == "slug":
            return serializers.SlugField(
                default=settings.default,
                max_length=settings.max_length,
                min_length=settings.min_length,
            )

        if settings.format == "url":
            return serializers.URLField(
                default=settings.default,
                max_length=settings.max_length,
                min_length=settings.min_length,
            )

        if settings.format == "uuid":
            return serializers.UUIDField(default=settings.default)

        if settings.format == "file_path":
            return serializers.FilePathField(
                default=settings.default,
                path=settings.path,
                match=settings.match,
                recursive=settings.recursive,
                allow_files=settings.allow_files,
                allow_folders=settings.allow_folders,
            )

        if settings.format == "ipv6":
            return serializers.IPAddressField(default=settings.default, protocol="IPv6")

        if settings.format == "ipv4":
            return serializers.IPAddressField(default=settings.default, protocol="IPv4")

        if settings.format == "ip":
            return serializers.IPAddressField(default=settings.default, protocol="both") 
开发者ID:rsinger86,项目名称:drf-typed-views,代码行数:61,代码来源:validator_factory.py


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