A modern, Django model field for generating short, unique, URL-safe UUIDs using the shortuuid lib.
Project description
django-shortuuid
A drop-in Django model field for generating short, URL-safe, and unique IDs using shortuuid.
Customizable, migration-friendly, with optional collision detection and Django admin integration.
Features
- Short, URL-safe unique IDs for Django models (default 22 characters, configurable)
- Customizable alphabet, prefix, and length
- Optional database collision detection and retry logic
- Django admin: field is read-only but visible
- Compatible with Django migrations
- Python type hints
Installation
pip install django-shortuuid
Usage
from django.db import models
from django_shortuuid.fields import ShortUUIDField
class MyModel(models.Model):
id = ShortUUIDField(primary_key=True, prefix="id-")
# ... other fields ...
By default, auto=True generates a unique short UUID when each instance is saved, and makes the field read-only in forms/admin.
Example
See django_example/ for a full Django setup and admin usage.
Configuration
auto: Generate and set value automatically (Trueby default)length: Length of the generated unique string (default22)prefix: Optional string prefix for the field valuealphabet: Custom alphabet for uuid generation (default:shortuuid’s default)collision_check: Enables collision checking in the database (Trueby default)max_retries: Max attempts to generate unique value before error (10by default)
License
Credits
This project was inspired by benrobster/django-shortuuidfield
and builds on ideas from the original implementation.
Special thanks to shortuuid for the short, URL-safe UUID generation.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_shortuuid-0.1.2.tar.gz.
File metadata
- Download URL: django_shortuuid-0.1.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8038af51e614dfd8f870343787a274fe4570897bb64261efba6f751e173c629c
|
|
| MD5 |
12d01c2de1cf689af57bf155af556f04
|
|
| BLAKE2b-256 |
742224c4e9f64a1255cdd132c51e604894ee99295cda3231a0b269dc81b08142
|
File details
Details for the file django_shortuuid-0.1.2-py3-none-any.whl.
File metadata
- Download URL: django_shortuuid-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
623e7607133d3fbf1031af0944f2cdf3a62af723fb0f5250c508876205be0aaf
|
|
| MD5 |
e5ef396ef17c9c5d1a267409cc34097d
|
|
| BLAKE2b-256 |
c06159af2881cab219437b3913fbf77f11d299cbdf1a05faeb7b71cf86a86236
|