Short-form UUID field for Django 1.8 and above
Project description
Installation
Installation using pip:
pip install django-smalluuid
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
Release history Release notifications | RSS feed
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.0.0.tar.gz
(6.8 kB
view hashes)
Built Distribution
Close
Hashes for django_smalluuid-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9879347f09781bef19abd4c34331b5e3dc0e829e535f3547e6929fd2f716b334 |
|
MD5 | f560367b94ef69375acb50db39727b07 |
|
BLAKE2b-256 | 658fb1153f692eb9fec6a5e7972ef00f53f95fd3a7c12c84e1ba3d1ec98bdf12 |