Skip to main content

PyPI latest GitHub Actions

About

Pretty UID fields for your Django models, with customizable prefixes and controlled length. Tested against Python 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 and Django 2.2, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1.

Usage

See examples below. You can optionally inherit your models from UIDModel, which gracefully handles IntegrityError 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)

Adding a UIDField to an existing model

You can populate the field with a data-migration:

def populate_uid(apps, schema_editor):
    User = apps.get_model("users", "User")

    for user in User.objects.all():
        user._meta.get_field("uid").populate(user, force_renew=True)
        user.save()


class Migration(migrations.Migration):
    operations = [migrations.RunPython(code=populate_uid)]

Note that the 3-attempt deduplication mechanism will not work, and you can get an error if you have a lot of objects and a small max_length.

Changelog

Metadata

Release files for django-uidfield 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-uidfield 0.3.5
File Size Uploaded Provenance
django_uidfield-0.3.5.tar.gz 5.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-uidfield 0.3.5
File Interpreter ABI Platform
django_uidfield-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / django_uidfield-0.3.5.tar.gz

Download URL django_uidfield-0.3.5.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ce180adc4b70ad0049b3668d025ee69b2b5374f1484fde7e17f8332ab7014a7f
BLAKE2b-256 checksum
How to use checksums
4fddb79633e08ace69355986f0000075a82716a33125cc25d7101ff1e32c6035
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release files / django_uidfield-0.3.5-py3-none-any.whl

Download URL django_uidfield-0.3.5-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94cbf5adaa3a0e9c7b5e32178e1fc69bcc51d4050c2b51c9f1577850f34bb584
BLAKE2b-256 checksum
How to use checksums
33f1c17db33ce7677241222b02389922142d83bbbc620b46e6dcf7a7c97f49f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Security for django-uidfield 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page