Skip to main content

A decoder/encoder Field for uuid

Project description

django-nativeshortuuidfield

Tests Linters

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: default True
    • This setting is to autofill search_uuid_fields in the ModelAdmins that inherits NativeUUIDSearchMixin with all shortuuid fields that are in the search_fields array. if you turned it off, you'll need to define search_uuid_fields on you ModelAdmin in order to search on shortuuid fields

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-nativeshortuuidfield-1.4.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_nativeshortuuidfield-1.4.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file django-nativeshortuuidfield-1.4.0.tar.gz.

File metadata

File hashes

Hashes for django-nativeshortuuidfield-1.4.0.tar.gz
Algorithm Hash digest
SHA256 c29cd31d79b0fde2f5a0983c5db0aa00a6d900a4e01489c1a1b63e43cd56d551
MD5 bb86decb4b94cb7ee47ccb80dd3e9ce5
BLAKE2b-256 6b7b6a3a814e26c90f33f25cff35b481f88c9dc3830080922caf324faaa22b6c

See more details on using hashes here.

File details

Details for the file django_nativeshortuuidfield-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_nativeshortuuidfield-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da4e8d7a071023e8a3fd4ddc8dd715fc7f6f320db8ecea5a62dddb1b108c853a
MD5 32203c35ca9c427a6844ee35e678b786
BLAKE2b-256 296c41595498d3807c4f6e25cee511d7f84beaf16a5c46968cc99f2643bec66d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page