Registry / web-framework / django-object-actions

django-object-actions

JSON →
library5.1.2pypypi✓ verified 25d ago

django-object-actions is a Django app that provides an easy way to add custom object-level actions to your Django admin interface. Instead of model-wide actions, these are specific to individual objects, appearing on the change page. The current version is 5.0.0, with minor releases occurring every few months and major breaking changes typically yearly, often tied to Django or Python version support updates.

pip install django-object-actions
INSTALL
IMPORT
SIG · DJANGO-OBJECT-ACTI
D
django-object-actions
web-frameworkpythonv5.1.2
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ObjectActions
from django_object_actions import ObjectActions
from django_object_actions import ObjectActions

This quickstart demonstrates how to add object-level actions to a Django ModelAdmin. It shows both the legacy method of listing action names in the `objectactions` attribute and the more modern `@object_action` decorator (introduced in v4.1.0) which allows for richer metadata like labels and descriptions. Actions appear on the change page of individual model objects in the Django admin.

import os from django.contrib import admin from django.db import models from django.http import HttpResponseRedirect from object_actions import ObjectActions, object_action # Define a simple model for demonstration class MyModel(models.Model): name = models.CharField(max_length=100) value = models.IntegerField(default=0) def __str__(self): return self.name class Meta: app_label = 'myapp' # Ensure app_label is set for isolated example # Configure admin with object actions class MyModelAdmin(ObjectActions, admin.ModelAdmin): list_display = ('name', 'value') objectactions = ['reset_value_legacy'] # Old way to register actions def reset_value_legacy(self, request, obj): obj.value = 0 obj.save() self.message_user(request, f"Value for {obj.name} reset to 0.") return HttpResponseRedirect(request.get_full_path()) @object_action(label='Increment Value', description='Increments the object\'s value by 1.') def increment_value_decorator(self, request, obj): obj.value += 1 obj.save() self.message_user(request, f"Value for {obj.name} incremented to {obj.value}.") return HttpResponseRedirect(request.get_full_path()) # In a real Django project, you would register this in myapp/admin.py # For this standalone example, we just define it. # Example usage (conceptual, for actual setup you need a Django project): # 1. Add 'object_actions' to INSTALLED_APPS in settings.py # 2. Add 'myapp' to INSTALLED_APPS (if MyModel is in myapp) # 3. In myapp/admin.py: # admin.site.register(MyModel, MyModelAdmin) print("To use, add 'object_actions' to INSTALLED_APPS and register your ModelAdmin inheriting from ObjectActions.") print("Define methods on your ModelAdmin and list them in 'objectactions' or use the @object_action decorator.")
Debug
Known issues
breakingOlder Python versions are no longer supported. v2.0.0 dropped Python 2, v3.0.0 dropped Python 3.4, and v4.0.0 dropped Python 3.6. The current version (v5.0.0) requires Python >= 3.9.
fix
Upgrade your Python environment to 3.9 or newer before installing django-object-actions v5.0.0+.
affects: <5.0.0
gotchaObject action methods must accept at least `request` and `obj` as arguments. An optional third argument `form` can be added if your action needs to interact with the model's admin form.
fix
Ensure your action method signatures conform to `def my_action(self, request, obj):` or `def my_action(self, request, obj, form):`.
affects: All versions
gotchaBy default, object actions require the user to have 'change' permissions for the model. If a user lacks this permission, the action button will not be visible. Custom permission checks can be implemented.
fix
For custom permission handling, override `has_change_permission` on your ModelAdmin, or for decorator-based actions, use the `permission_required` argument on `@object_action`.
affects: All versions
gotchaIt's crucial for object action methods to return an `HttpResponse` (e.g., `HttpResponseRedirect`) or `None`. If `None` is returned, the user will remain on the same page. Not returning a valid HTTP response can lead to unexpected behavior.
fix
Always return an `HttpResponseRedirect(request.get_full_path())` to refresh the page after an action, or another appropriate `HttpResponse`.
affects: All versions
gotchaWhile listing action names in the `objectactions` attribute still works, the `@object_action` decorator (introduced in v4.1.0) is the recommended modern approach as it allows specifying a `label`, `description`, `attrs`, and `permission_required` directly on the method.
fix
For new actions, prefer using the `@object_action` decorator. For existing actions, consider refactoring to use the decorator for better maintainability and clearer metadata.
affects: <4.1.0 (for missing decorator features)
Upgrade
Version history
5.1.2latest on PyPI · released May 28, 2026
Audit
Dependencies
djangorequiredCore functionality as a Django app, requires Django to run.
Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
django-object-actions — pip install django-object-actions · libregistry