django-class-based-admin-actions
Django admin actions written as classes and composed from mixins, the way class-based views are.
AdminAction.as_action() is to admin actions what View.as_view() is to views.
INSTALLED_APPS = [..., "class_based_admin_actions"] # needed for the confirmation template
from class_based_admin_actions import (
ClassActionsMixin, ConfirmationMixin, CsvExportAction, FormUpdateAction, UpdateAction,
)
class PublishAction(UpdateAction):
description = "Publish selected %(verbose_name_plural)s"
update_fields = {"status": "published"}
success_message = "Published %(count)d %(name)s."
allowed_permissions = ("change",)
class ArchiveAction(ConfirmationMixin, PublishAction): # reuse + ask first
update_fields = {"status": "archived"}
class SetStatusAction(FormUpdateAction): # ask for values in a form
form_class = StatusForm
@admin.register(Article)
class ArticleAdmin(ClassActionsMixin, admin.ModelAdmin):
actions = [PublishAction, ArchiveAction, SetStatusAction,
CsvExportAction.as_action(fields=["title", "status"])]
Classes can go straight in actions with ClassActionsMixin; without it use X.as_action(**overrides)
(also fine for admin.site.add_action).
Hierarchy
AdminAction setup / dispatch / has_permission / handle / run / perform / finish
├─ BulkAction = QuerysetMixin + SuccessMessageMixin + AtomicMixin + AdminAction
│ ├─ ObjectAction process_object(obj), skip_errors, log_message
│ └─ UpdateAction update_fields -> queryset.update()
│ └─ FormUpdateAction FormMixin + UpdateAction
└─ CsvExportAction fields, filename, CSV-injection safe
| Mixin | Adds |
|---|---|
QuerysetMixin |
select_related, prefetch_related, max_objects |
SuccessMessageMixin |
success_message with %(count)d, %(name)s |
AtomicMixin |
transaction around the run, using |
TemplateResponseMixin |
admin-context intermediate page |
ConfirmationMixin |
confirm page before perform() |
FormMixin |
form on the confirm page (form_class, initial, form_valid/invalid) |
All hooks call super(), so mixins combine in any order; put them before the base class.
Write your own by overriding a hook (check_preconditions, get_queryset, run, on_success, ...).
Raise ActionError("msg") anywhere to abort with an error message (and roll back under AtomicMixin).
Notes
- Permissions:
allowed_permissionsis Django's mechanism (action hidden unless any listedhas_<perm>_permissionpasses) and is re-checked on dispatch. Overridehas_permission()for more. descriptionis%-formatted by Django withverbose_name/verbose_name_plural; escape literal%as%%.- The confirmation page posts back to the changelist; the form must not define fields named
action,select_acrossor_selected_action. UpdateActionusesQuerySet.update()(nosave(), signals, orauto_now); useObjectActionif you need them.
Development
uv pip install -e . pytest pytest-django && pytest
Metadata
Release files for django-class-based-admin-actions 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_class_based_admin_actions-0.1.0.tar.gz | 12.4 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_class_based_admin_actions-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.3 kB
Release files / django_class_based_admin_actions-0.1.0.tar.gz
| Download URL | django_class_based_admin_actions-0.1.0.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c242b4fe0b39966d6e9879b5ebeb4fd68b00f2b5eddb98a228bd4e1b7ae06e0
|
|
BLAKE2b-256 checksum How to use checksums |
5f1f29563e3fad846425b5b8bad98d56db3a4a24b77503bf5357a1df533b7cf2
|
| 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 20, 2026.
Transparency logRelease files / django_class_based_admin_actions-0.1.0-py3-none-any.whl
| Download URL | django_class_based_admin_actions-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8ec265d13e45ddf0e9815a57737ae9ffc85bd7850c640bfdc73b90f6a4c8590
|
|
BLAKE2b-256 checksum How to use checksums |
9aab1dd58d11ee2c71133e6f07f2d956d907769a8d99d143f3aed969a0598087
|
| 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 20, 2026.
Transparency logSecurity for django-class-based-admin-actions 0.1.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_class_based_admin_actions-0.1.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 Oct 20, 2026.
Transparency logA 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.