Next generation NanoID in Django Model IDs
Project description
Django NanoID Field
NanoID is an alternative to UUID, CUID for generating random IDs. This package provides a field to use in models.
Roadmap
- Create
AutoField
that uses NanoID instead of regular integer ID.
Installation
Install it from PyPI:
pip install django-nanoid-field
Usage
First, add it to your applications (Not Required)
INSTALLED_APPS = [
# ...
'nanoid_field',
# ...
]
You can now use it in your models like:
from django.db import models
from nanoid_field import NanoidField
class Profile(models.Model):
hash = NanoidField(max_length=10, alphabet='0123456789abcdefghijklmnopqrstuvwxyz)
NanoidField
This model field is based on CharField
. All of it's parameters can be used.
Additionally following fields affects outcome of NanoID:
max_length
Parameter (Optional)
Determines size of the generated ID as well as length of the field in Database.
DEFAULT:
21
alphabet
Parameter (Optional)
This optional parameter helps you to determine which characters will be used to build up.
DEFAULT:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-
Using NanoidField as primary_key
To use NanoID as default primary_key
you need to explicitly define it in your
model:
from django.db import models
class SomeModel(models.Model):
id = NanoidField()
# ...
Changing defaults
django-nanoid-field
also provides two settings to change defaults of alphabet
and max_length
. You can change those by adding them to your settings.py
file
# settings.py file
NANOID_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-"
NANOID_SIZE = 21
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
File details
Details for the file django_nanoid_field-0.1.4.tar.gz
.
File metadata
- Download URL: django_nanoid_field-0.1.4.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df453208733c29f4af295f4fdd74ccc18d3203e4ac2cb0267ef0ba93f09140c2 |
|
MD5 | 9cf3e02c13aa0da279101b1d04b05266 |
|
BLAKE2b-256 | abf4dd7d32366681fa608fd9207eec1bdcc960e9225a2d2523fa7f75466cc3f4 |
File details
Details for the file django_nanoid_field-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: django_nanoid_field-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c55d8c308d609dfe62ac9e4a1482eb9f7642997852a920b827748e660577b6e |
|
MD5 | 7c1d9fbe85f90da81392da1c3a9a4e6c |
|
BLAKE2b-256 | 8d01b13d05ce78a412ffcae77904ea08d5ee919676c7eb729825248b68d32eb5 |