| 1 |
django-shortuuidfield |
| 2 |
---------------- |
| 3 |
|
| 4 |
Provides a ShortUUIDField for your Django models which uses the base-57 "Short UUID" package at https://github.com/stochastic-technologies/shortuuid/ . |
| 5 |
|
| 6 |
Originally, a fork from David Cramer's excellent django-uuidfield, but not much is left of that besides a bit of structure. |
| 7 |
|
| 8 |
Installation |
| 9 |
============ |
| 10 |
|
| 11 |
Install it with pip (or easy_install):: |
| 12 |
|
| 13 |
pip install django-shortuuidfield |
| 14 |
|
| 15 |
Usage |
| 16 |
===== |
| 17 |
|
| 18 |
First you'll need to attach a ShortUUIDField to your class. This acts as a char(22) to maintain compatibility with SQL versions:: |
| 19 |
|
| 20 |
from shortuuidfield import ShortUUIDField |
| 21 |
|
| 22 |
class MyModel(models.Model): |
| 23 |
uuid = ShortUUIDField() |
| 24 |
|
| 25 |
Enjoy! |
| 26 |
|
| 27 |
Notes |
| 28 |
===== |
| 29 |
|
| 30 |
* ShortUUIDField is a subclass of django.db.models.CharField |
| 31 |
|
| 32 |
* You can pass usual Django CharField parameters on init, although some of them are added/overwritten: |
| 33 |
+ max_length=22 (since we are using base-57 format which is fixed at 22 characters) |
| 34 |
+ blank=True, editable=False (set auto=False to remove these fields enforcement) |
| 35 |
|
| 36 |
* Uses shortuuid.uuid() that generates uuid4 random values |