Python rest_framework.serializers.UUIDField() Examples

The following are 3 code examples for showing how to use rest_framework.serializers.UUIDField(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module rest_framework.serializers , or try the search function .

Example 1
Project: koku   Author: project-koku   File: view.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example 2
Project: graphene-django   Author: graphql-python   File: test_field_converter.py    License: MIT License 5 votes vote down vote up
def test_should_uuid_convert_string():
    if hasattr(serializers, "UUIDField"):
        assert_conversion(serializers.UUIDField, graphene.String) 
Example 3
Project: drf-typed-views   Author: rsinger86   File: validator_factory.py    License: MIT License 4 votes vote down vote up
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")