Skip to main content

Short-form UUID field for Django 1.8 and above

Project description

https://img.shields.io/pypi/v/django-smalluuid.svg https://img.shields.io/pypi/dm/django-smalluuid.svg https://img.shields.io/github/license/adamcharnock/django-smalluuid.svg https://img.shields.io/travis/adamcharnock/django-smalluuid.svg https://coveralls.io/repos/adamcharnock/django-smalluuid/badge.svg?branch=master

Installation

Installation using pip:

pip install django-smalluuid

Tested on:

  • Django >= 2.2 <= 4.0

  • Python 3.7, 3.8, 3.9, 3.10

Basic Usage

To get started use the SmallUUIDField field in your model definitions:

from django.db import models
from django_smalluuid.models import SmallUUIDField, uuid_default

class ExampleModel(models.Model):
    uuid = SmallUUIDField(default=uuid_default())

The field provides values as instances of SmallUUID (see smalluuid):

>>> obj = ExampleModel.objects.create()

# The initial UUID has been auto-generated by uuid_default()
>>> obj.uuid
SmallUUID('T1q_P6HcQNSyW6tpqJTxww')

# It is still available in the groupex hex form (if needed)
>>> obj.hex_grouped
'4f5abf3f-a1dc-40d4-b25b-ab69a894f1c3'

# Filtering is done on the shortened UUIDs
>>> ExampleModel.objects.filter(uuid='T1q_P6HcQNSyW6tpqJTxww')
[<ExampleModel: ExampleModel object>]

Typed Usage

django-smalluuid also supports the Typed UUID’s as provided by smalluuid. This allows for the object’s type to be stored within the UUID.

Updating the above example:

from django.db import models
from django_smalluuid.models import SmallUUIDField, uuid_typed_default

class TypedExampleModel(models.Model):
    uuid = SmallUUIDField(default=uuid_typed_default(type=42))

Which can be interacted with as follows:

>>> obj = TypedExampleModel.objects.create()
>>> obj.uuid
TypedSmallUUID('qvyk8nzbQfu8zAnTPQweyw')
>>> obj.uuid.type
42

Credits

django-smalluuid is packaged using seed and relies upon smalluuid.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-smalluuid-1.2.1.tar.gz (8.8 kB view details)

Uploaded Source

File details

Details for the file django-smalluuid-1.2.1.tar.gz.

File metadata

  • Download URL: django-smalluuid-1.2.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.7

File hashes

Hashes for django-smalluuid-1.2.1.tar.gz
Algorithm Hash digest
SHA256 a84916671992bf3f61987463964b653db7073d48c00bbc7673a47a106681c13c
MD5 49ea82120780b4769d4072b69b1f3847
BLAKE2b-256 85265c9bf95f0140461cd350cb9ffae3301f7a3d2409e662579c7c8293d96a76

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page