27medkamal / django-uidfield

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status PyPI version

About

Pretty UID fields for your Django models, with customizable prefixes and controlled length. Tested vs. Python 2.7, 3.5, 3.6 and Django 1.8 - 1.11.

Usage

See examples below. You can optionally inherit your models from UIDModel, which gracefully handles IntergrityError on saving UIDs, making up to 3 attempts with random UIDs. Integrity errors should be pretty rare if you use large enough max_length on your fields, but you may still want to use it for extra safety.

from django_uidfield.fields import UIDField


class YourModel(models.Model):
    uid_field = UIDField(prefix='tmp_', max_length=20)
    
# the value will be like 'tmp_Akw81LmtPqS93dKb'

or

from django_uidfield.models import UIDModel
from django_uidfield.fields import UIDField


class YourModel(UIDModel):
    uid_field = UIDField(prefix='tmp_', max_length=20)

About

License:MIT License


Languages

Language:Python 100.0%