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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibcpy 3.10–3.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.fixUpgrade 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.fixEnsure 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.fixFor 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.fixAlways 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.fixFor 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.