A decoder/encoder Field for uuid
Project description
django-nativeshortuuidfield
Provides a NativeShortUUIDField for your Django models which uses the base-57 "Short UUID" package at https://github.com/stochastic-technologies/shortuuid/ to be used in Python and store it as full UUID in database.
Installation
Install it with pip (or easy_install):
$ pip install django-nativeshortuuidfield
Usage
First you'll need to add a NativeShortUUIDField to your class:
from native_shortuuid import NativeShortUUIDField
class MyModel(models.Model):
uuid = NativeShortUUIDField(unique=True, default=uuid.uuid4)
If you want to add the ability to search by shortuuid in ModelAdmin
you need to inherit NativeUUIDSearchMixin
from native_shortuuid.admin import NativeUUIDSearchMixin
@admin.register(models.MyModel)
class MyModelAdmin(NativeUUIDSearchMixin, admin.ModelAdmin):
search_fields = ('uuid', )
If you want to have to ability to write your own uuid search fields list
from native_shortuuid.admin import NativeUUIDSearchMixin
@admin.register(models.MyModel)
class MyModelAdmin(NativeUUIDSearchMixin, admin.ModelAdmin):
admin_auto_extract_uuid_search_fields = False
search_fields = ('name', )
search_uuid_fields = ['uuid', 'foreign_model__uuid']
Enjoy!
Settings
ADMIN_AUTO_EXTRACT_UUID_SEARCH_FIELDS
: defaultTrue
- This setting is to autofill
search_uuid_fields
in the ModelAdmins that inheritsNativeUUIDSearchMixin
with all shortuuid fields that are in thesearch_fields
array. if you turned it off, you'll need to definesearch_uuid_fields
on you ModelAdmin in order to search on shortuuid fields
- This setting is to autofill
Notes
-
NativeShortUUIDField is a subclass of django.db.models.UUIDField
-
You can pass usual Django UUIDField parameters on init, although some of them are added/overwritten:
- blank=True, editable=False (set auto=False to remove these fields enforcement)
Contribution Notes
Pull Request
- Increase the version number in the
setup.py
to the new version that the new pull request represents.
Publishing the Package
After the pull request gets merged into the master branch a new release should be created
-
Create a new tag with the same version number you updated the
setup.py
with:$ git checkout master $ git tag -a 2.1.0 -m 'fix importing order' $ git push origin 2.1.0
-
Go to GitHub's releases section and create a new release:
- Chose the tag version that you just created
- Fill the release title with the same version number
- Add a description of the release and publish it
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
Hashes for django-nativeshortuuidfield-1.4.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6572f575d4ca29b35f5626130f04cf3e8e7261237782dd09264b1531f1a3601c |
|
MD5 | 8099eed22d94c771c59382a1ddad9fe9 |
|
BLAKE2b-256 | ba50dc80235944f88973e88fc4844eb1d6d60ab72bb7d8c70929d44a560c72da |
Hashes for django_nativeshortuuidfield-1.4.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84821909f38bb04894b751e9bdc024751e3c2a5808ba92a7c5b306eef3a7fd36 |
|
MD5 | 747df20ecb331e97c94c9fe4a79a45f2 |
|
BLAKE2b-256 | 28e555d9764c9f0d0d2618fc6dd52379ea83726d412e4827ca580e7385857c26 |