Skip to main content

django-display-ids

PyPI Python Django CI codecov Docs License: MIT

Stripe-style prefixed IDs for Django, like inv_2aUyqjCzEIiEcYMKj7TZtw, on top of the UUID fields you already have. No new fields and no migrations.

from django_display_ids import DisplayIDMixin, DisplayIDModel

class Invoice(DisplayIDModel):
    display_id_prefix = "inv"
    id = models.UUIDField(primary_key=True, default=uuid.uuid7)
    slug = models.SlugField(unique=True)

invoice.display_id  # "inv_2aUyqjCzEIiEcYMKj7TZtw"

class InvoiceDetailView(DisplayIDMixin, DetailView):
    model = Invoice

The view now finds the invoice from the display ID, the UUID (550e8400-e29b-41d4-a716-446655440000, in either case) or the slug. Each one becomes a plain query on the UUID or slug column.

A UUID in a URL or log doesn't say what it points to; a display ID does. The part after the prefix is the same UUID in base62, so it converts back without a database lookup.

Django REST Framework

from django_display_ids.contrib.rest_framework import (
    DisplayIDField,
    DisplayIDMixin,
    DisplayIDRelatedField,
)

class InvoiceSerializer(serializers.ModelSerializer):
    display_id = DisplayIDField()  # "inv_..."
    customer = DisplayIDRelatedField(queryset=Customer.objects.all())

    class Meta:
        model = Invoice
        fields = ("display_id", "customer", "total")

class InvoiceViewSet(DisplayIDMixin, ModelViewSet):
    queryset = Invoice.objects.all()
    serializer_class = InvoiceSerializer

The viewset finds invoices by display ID, UUID or slug. customer shows up as "cust_..." in responses and accepts the same in requests, so clients can send back what they read. With drf-spectacular, the fields and the viewset's {id} parameter get OpenAPI schemas.

Admin

from django_display_ids import DisplayIDAdminSearchMixin

@admin.register(Invoice)
class InvoiceAdmin(DisplayIDAdminSearchMixin, admin.ModelAdmin):
    list_display = ["display_id", "name"]
    search_fields = ["name"]

The admin search box finds invoices by display ID, UUID or slug, alongside the usual search.

Installation

pip install django-display-ids
pip install "django-display-ids[drf]"          # with Django REST Framework
pip install "django-display-ids[spectacular]"  # with DRF and drf-spectacular

Requires Python 3.12+ and Django 4.2+.

What's included

  • DisplayIDModel for the display_id property, and a manager with get_by_identifier(), filter_by_identifier(), get_by_identifiers() and resolve_uuid()
  • resolve_object() and resolve_objects() to look up one or many identifiers anywhere else
  • DisplayIDMixin for Django class-based views and for DRF views
  • DisplayIDField and DisplayIDRelatedField for DRF serializers, so APIs can both show and accept display IDs, with drf-spectacular schemas
  • DisplayIDAdminSearchMixin to search the admin by display ID, UUID or slug
  • URL converters, and a display_id template filter for any UUID
  • DisplayIDType for IDs with no model behind them, like request IDs

Documentation

django-display-ids.readthedocs.io

Contributing

See CONTRIBUTING.md.

These generate and store prefixed IDs in a new model field, where django-display-ids works with the UUID fields you already have:

Metadata

Release files for django-display-ids 0.8.2

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-display-ids 0.8.2
File Size Uploaded Provenance Actions
django_display_ids-0.8.2.tar.gz 31.0 kB With provenance Details for django_display_ids-0.8.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-display-ids 0.8.2
File Interpreter ABI Platform Actions
django_display_ids-0.8.2-py3-none-any.whl Python 3 none any Details for django_display_ids-0.8.2-py3-none-any.whl

Total release size: 74.3 kB

Release files / django_display_ids-0.8.2.tar.gz

Download URL django_display_ids-0.8.2.tar.gz
Size 31.0 kB
Tags Source
SHA-256 checksum
How to use checksums
11451f36e9aced6e7686d6b0edd69f7ab4be12aa5843712031719cd92ea5fe16
BLAKE2b-256 checksum
How to use checksums
e4d261401552cca76786ad8a026c81118ec01e52bac11d29810bf30501419640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / django_display_ids-0.8.2-py3-none-any.whl

Download URL django_display_ids-0.8.2-py3-none-any.whl
Size 43.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad92477c021d9e20677118572a5a7d178e16d621d7dbf8e9a94d73668e54a3fb
BLAKE2b-256 checksum
How to use checksums
60ad8a54adb1f475cba7016f2ec854af2c471b6f219d2a25785bbbbb813eb117
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Security for django-display-ids 0.8.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_display_ids-0.8.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

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