Skip to main content

Short-form UUID field for Django 1.8 and above

Project description


Installation using pip:

pip install django-smalluuid

Tested on:

  • Django >= 1.8 <= 1.11
  • Python 2.7, 3.4, 3.5, 3.6

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

# It is still available in the groupex hex form (if needed)
>>> obj.hex_grouped

# 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
>>> obj.uuid.type


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.

Files for django-smalluuid, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size django_smalluuid-1.2.0-py3-none-any.whl (9.2 kB) File type Wheel Python version 3.8 Upload date Hashes View
Filename, size django-smalluuid-1.2.0.tar.gz (7.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page