A model base class which provides custom designed random integer primary keys to you Django models.
Project description
Django Random ID
A model base class which provides custom designed random integer primary keys to you Django models.
Installation
Run the following to install:
pip install django_random_id
Usage
The original way of creating and assigning primary keys in Django models
from django.db import models
class CustomUser(models.Model):
name = models.CharField(max_length=30, blank=False)
steve = CustomUser.objects.create(name="Steve")
bill = CustomUser.objects.create(name="Bill")
print(steve.id)
# >>> '1'
print(bill.id)
# >>> '2'
The primary keys are auto-incremental integers.
Now, let's see how RandomIDModel
helps you:
from django.db import models
from django_random_id import RandomIDModel
class CustomUser(RandomIDModel):
name = models.CharField(max_length=30, blank=False)
steve = CustomUser.objects.create(name="Steve")
bill = CustomUser.objects.create(name="Bill")
print(steve.id)
# >>> '425291518806427'
print(bill.id)
# >>> '607559381880556'
The Random primary ID is guaranteed to be unique.
By default the ID will be 16 digits long, but you can change this in
settings.py with the RANDOM_ID_MODEL_LENGTH
setting.
You can also use RandomAlphaNumIDModel
base model to generate string
alphanumerical primary keys.
Testing - In Progress
To install django_random_id, along with the tools you need to develop and run the tests, run the following in your virtual environment:
$ pip install -e .[dev]
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_random_id-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef026c5cbee06cb56c1f250434d3d9162d55e1340b4167e5bc0da7f42b65a10e |
|
MD5 | f411dac4fb881a455d7af89484a541ab |
|
BLAKE2b-256 | 90cf7bad67c89b9dc8b0d9edcedb82e7552885b143d570d26e892a02ff199081 |