Skip to main content

ULID (Universally Unique Lexicographically Sortable Identifier) support for Django.

Project description

python-ulid-django

ULID (Universally Unique Lexicographically Sortable Identifier) support for Django.

This package uses the ULID type implemented by python-ulid.

This package is heavily inspired by django-ulid. The reason I'm reinventing the wheel is that I want to use python-ulib's ULID implementation.

Usage

Installation

pip install python-ulid-django

Model Field

You can then add ULIDField to your Django model just like other fields.

Example:

from django.contrib.auth.models import AbstractUser
from ulid import ULID
from ulid_django.models import ULIDField


class User(AbstractUser):
    id = ULIDField(primary_key=True, default=ULID, editable=False)

URL Converter

There is also a URL converter can be used.

from django.urls import path, register_converter
from ulid import ULID
from ulid_django.converters import ULIDConverter


def user_detail_view(request, user_id):
    assert isinstance(user_id, ULID)
    ...


register_converter(ULIDConverter, "ulid")

urlpatterns = [
    path("user/<ulid:user_id>/", user_detail_view),
    ...,
]

Development

Prerequisite: PDM

Environment setup: pdm sync

Run linters: pdm lint

Test: pdm test

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

python_ulid_django-1.4.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

python_ulid_django-1.4.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file python_ulid_django-1.4.0.tar.gz.

File metadata

  • Download URL: python_ulid_django-1.4.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.13.6 Windows/11

File hashes

Hashes for python_ulid_django-1.4.0.tar.gz
Algorithm Hash digest
SHA256 38d42dff556c0922bde117969c75d610648b3a8aa8e7eb64197af109c7db489e
MD5 2359f071b1cd750fd042af92c593b880
BLAKE2b-256 ffd9b138bb6c71b7da0daaf6f40deef21c0264896b6bf0d8c39089016cd7b2b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_ulid_django-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 644fc09b4a8b696c1a46db42dd7b25d57d6e6a2f4b104c7f595fff99fa2d2e85
MD5 49f65c87b331708fe7339c6b96aed20d
BLAKE2b-256 863b83e8bdc5a5e1ede1eaffe2847eb192608316abc68ebb5eff4dbc75817b95

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