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(), 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

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.0

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.0
File Size Uploaded Provenance Actions
django_display_ids-0.8.0.tar.gz 27.1 kB With provenance Details for django_display_ids-0.8.0.tar.gz

Built distribution (wheel)

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

Total release size: 64.7 kB

Release files / django_display_ids-0.8.0.tar.gz

Download URL django_display_ids-0.8.0.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
751432dcd79235b9853edf0b8e01369fae35ab33e9840de3df9a68cd57af9ce0
BLAKE2b-256 checksum
How to use checksums
18aad5e86754436bf0554932cccb9009a92aae61d18f2c1dfbb54de9ea77b192
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 Sep 29, 2026.

Transparency log

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

Download URL django_display_ids-0.8.0-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ec4572d0f8134382de8f0848fff40acfd542f6bb9f2622af3656b14a82ad4c3
BLAKE2b-256 checksum
How to use checksums
4d1a1cf80ba0b773130746a935de9a447f796561e2998bbd4f066e5cc3690612
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 Sep 29, 2026.

Transparency log

Security for django-display-ids 0.8.0

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.0.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 Sep 29, 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