Skip to main content

Django Utils

CI on master Coverage on master PyPI version Python versions Documentation

The data__filling dropdown filter open in the Django admin sidebar, listing Avocado, Bacon, Cheddar, Corned Beef and Turkey

Django Utils is a collection of the small Django helpers, admin power-ups and ORM utilities that most projects end up writing themselves: JSON-aware admin filters, encrypted model fields, memory-bounded queryset iteration, resumable management commands, and more. It builds on the Python Utils library. It is by no means a complete collection, but it has served production projects well and keeps growing.

Full documentation, including a "why this over the alternatives" page, is at https://django-utils-2.readthedocs.io/en/latest/.

Requirements

  • Python 3.10+
  • Django 4.2, 5.2, or 6.0

Install

  1. Run pip install django-utils2
  2. Add django_utils to your INSTALLED_APPS

If you want to run the tests, install the tests extra (pip install "django-utils2[tests]") and run pytest.

Quickstart

Filter an admin changelist on a nested JSONField value without writing a custom SimpleListFilter:

from django.contrib import admin
from django_utils.admin.filters import JSONFieldFilterDropdown

from myapp.models import Sandwich


class SandwichAdmin(admin.ModelAdmin):
    list_filter = (
        JSONFieldFilterDropdown.create('data__filling'),
    )


admin.site.register(Sandwich, SandwichAdmin)

A sidebar filter on data['filling'], no JOIN or denormalized column. The quickstart page has two more features like this.

Features

Every feature below has its own page on the docs site, with runnable examples, edge cases, and (for the admin features) screenshots or a live in-browser demo.

  • Admin dropdown / Select2 / JSON filters: dropdown, autocomplete, and JSON sub-path list filters for the changelist sidebar, plus an operator selector (gte, lte, icontains, ...) for typed comparisons. See Select / dropdown / autocomplete filters and Operator filters.
  • JSON widget: a drop-in JSONField admin widget that pretty-prints and validates JSON as you type. See JSON widget.
  • Read-only admin: turn any ModelAdmin into a read-only view: add/change/delete denied for everyone, filtering and search still work. See Read-only admin.
  • Count columns: sortable related-object count columns for list_display, without the N+1 or JOIN fan-out footguns. See Count columns.
  • Admin export: streaming CSV/JSON export actions for the changelist, memory-bounded via queryset_iterator. See Export.
  • Choices: metadata-carrying choices with dict-like access and a real enum.Enum on demand via as_enum(). See Choices.
  • PostgreSQL ENUM field: a CharField backed by a native PostgreSQL ENUM type on Postgres, plain VARCHAR everywhere else, with hand-written migration operations for creating the type and adding values. See PostgreSQL ENUM field.
  • Request/user context (ASGI-safe): access the current request/user from anywhere via contextvars, isolated per asyncio task, unlike thread-local equivalents. See Current request / user (ASGI-safe).
  • Query budgets: catch N+1 regressions in production code paths, not just in tests, with a query-counting context manager/decorator. See Query budgets.
  • Auth helpers: superuser_required/staff_required decorators and a permission_string() builder for has_perm() checks. See Auth helpers.
  • Fetch-Metadata CSRF middleware: defense-in-depth CSRF hardening using the Sec-Fetch-Site header, run alongside (not instead of) Django's own CSRF middleware. See Fetch-Metadata CSRF middleware.
  • Subquery aggregates: SubqueryCount/SubquerySum/SubqueryAvg/... annotate each aggregate in its own subquery, avoiding the JOIN fan-out that multiplies counts. See Subquery aggregates.
  • Bulk upsert: bulk_update_or_create(): one INSERT ... ON CONFLICT DO UPDATE batch instead of a racy, two-query-per-row loop. See Bulk upsert.
  • Chunked management commands: ChunkedCommand: memory-bounded, resumable processing of large querysets with progress logging and a transactional dry-run. See ChunkedCommand.
  • Encrypted model fields: EncryptedCharField/EncryptedTextField/ EncryptedJSONField: Fernet-encrypted values in a plain TEXT column, with key-rotation support. See Encrypted model fields.

Metadata

Release files for django-utils2 4.1.3

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-utils2 4.1.3
File Size Uploaded Provenance Actions
django_utils2-4.1.3.tar.gz 64.5 kB With provenance Details for django_utils2-4.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-utils2 4.1.3
File Interpreter ABI Platform Actions
django_utils2-4.1.3-py3-none-any.whl Python 3 none any Details for django_utils2-4.1.3-py3-none-any.whl

Total release size: 142.1 kB

Release files / django_utils2-4.1.3.tar.gz

Download URL django_utils2-4.1.3.tar.gz
Size 64.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1a939cccabc4899d4979c7970eb5f9b621e4dfed0daa57841f52d165e3868655
BLAKE2b-256 checksum
How to use checksums
89da7296e9214982d79b87aebbbb6a3be15debe350d15808282f1a96adf5fbf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 28, 2026.

Transparency log

Release files / django_utils2-4.1.3-py3-none-any.whl

Download URL django_utils2-4.1.3-py3-none-any.whl
Size 77.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c53ef80da359fcd986f3d5549be2e244a50c250717df62f0e02ecb158aada630
BLAKE2b-256 checksum
How to use checksums
887ae277ba57e0ebe4029fa49f9e7b90e0ae60e4f978d8903b58347ba781b793
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 28, 2026.

Transparency log

Security for django-utils2 4.1.3

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_utils2-4.1.3.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 28, 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.

Release history Release notifications | RSS feed

This release

4.1.3 This release

2 release files Full provenance

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