{"id":13448742,"url":"https://github.com/crccheck/django-object-actions","last_synced_at":"2026-05-22T06:17:38.381Z","repository":{"id":5145342,"uuid":"6312523","full_name":"crccheck/django-object-actions","owner":"crccheck","description":"A Django app for easily adding object tools in the Django admin","archived":false,"fork":false,"pushed_at":"2025-04-05T06:32:48.000Z","size":359,"stargazers_count":743,"open_issues_count":29,"forks_count":85,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-05-11T00:11:23.915Z","etag":null,"topics":["django","django-admin","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-object-actions/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"arduino/Arduino","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crccheck.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-20T18:55:21.000Z","updated_at":"2025-05-05T07:12:47.000Z","dependencies_parsed_at":"2024-01-06T09:54:49.970Z","dependency_job_id":"302d12da-690b-435a-9f15-008bbe112772","html_url":"https://github.com/crccheck/django-object-actions","commit_stats":{"total_commits":256,"total_committers":33,"mean_commits":7.757575757575758,"dds":0.21484375,"last_synced_commit":"847846774442f20ac4ffc68f7f1f53707f53b209"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crccheck%2Fdjango-object-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crccheck%2Fdjango-object-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crccheck%2Fdjango-object-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crccheck%2Fdjango-object-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crccheck","download_url":"https://codeload.github.com/crccheck/django-object-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253650989,"owners_count":21942238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-admin","python"],"created_at":"2024-07-31T06:00:19.870Z","updated_at":"2026-05-22T06:17:33.346Z","avatar_url":"https://github.com/crccheck.png","language":"Python","funding_links":[],"categories":["Admin interface","管理界面","Python","Best Django Admin Interface Resources"],"sub_categories":["Admin Extensions \u0026 Functional Enhancements"],"readme":"# Django Object Actions\n\n[![CI](https://github.com/crccheck/django-object-actions/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/crccheck/django-object-actions/actions/workflows/ci.yml?query=branch%3Amain)\n\nIf you've ever tried making admin object tools you may have thought, \"why can't\nthis be as easy as making Django Admin Actions?\" Well now they can be.\n\n## Quick-Start Guide\n\nInstall Django Object Actions:\n\n```shell\n$ pip install django-object-actions\n```\n\nAdd `django_object_actions` to your `INSTALLED_APPS` so Django can find\nour templates.\n\nIn your admin.py:\n\n```python\nfrom django_object_actions import DjangoObjectActions, action\n\nclass ArticleAdmin(DjangoObjectActions, admin.ModelAdmin):\n    @action(label=\"Publish\", description=\"Submit this article\") # optional\n    def publish_this(self, request, obj):\n        publish_obj(obj)\n\n    change_actions = ('publish_this', )\n    changelist_actions = ('...', )\n```\n\n## Usage\n\nDefining new _tool actions_ is just like defining regular [admin actions]. The\nmajor difference is the functions for `django-object-actions` will take an\nobject instance instead of a queryset (see _Re-using Admin Actions_ below).\n\n_Tool actions_ are exposed by putting them in a `change_actions` attribute in\nyour `admin.ModelAdmin`. You can also add _tool actions_ to the main changelist\nviews too. There, you'll get a queryset like a regular [admin action][admin actions]:\n\n```python\nfrom django_object_actions import DjangoObjectActions\n\nclass MyModelAdmin(DjangoObjectActions, admin.ModelAdmin):\n    @action(\n        label=\"This will be the label of the button\",  # optional\n        description=\"This will be the tooltip of the button\" # optional\n    )\n    def toolfunc(self, request, obj):\n        pass\n\n    def make_published(modeladmin, request, queryset):\n        queryset.update(status='p')\n\n    change_actions = ('toolfunc', )\n    changelist_actions = ('make_published', )\n```\n\nJust like admin actions, you can send a message with `self.message_user`.\nNormally, you would do something to the object and return to the same url, but\nif you return a `HttpResponse`, it will follow it (hey, just like [admin\nactions]!).\n\nIf your admin modifies `get_urls`, `change_view`, or `changelist_view`,\nyou'll need to take extra care because `django-object-actions` uses them too.\n\n### Re-using Admin Actions\n\nIf you would like a preexisting admin action to also be an _object action_, add\nthe `takes_instance_or_queryset` decorator to convert object instances into a\nqueryset and pass querysets:\n\n```python\nfrom django_object_actions import DjangoObjectActions, takes_instance_or_queryset\n\nclass RobotAdmin(DjangoObjectActions, admin.ModelAdmin):\n    # ... snip ...\n\n    @takes_instance_or_queryset\n    def tighten_lug_nuts(self, request, queryset):\n        queryset.update(lugnuts=F('lugnuts') - 1)\n\n    change_actions = ['tighten_lug_nuts']\n    actions = ['tighten_lug_nuts']\n```\n\n[admin actions]: https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/\n\n### Customizing _Object Actions_\n\nTo give the action some a helpful title tooltip, you can use the `action` decorator\nand set the description argument.\n\n```python\n@action(description=\"Increment the vote count by one\")\ndef increment_vote(self, request, obj):\n    obj.votes = obj.votes + 1\n    obj.save()\n```\n\nAlternatively, you can also add a `short_description` attribute,\nsimilar to how admin actions work:\n\n```python\ndef increment_vote(self, request, obj):\n    obj.votes = obj.votes + 1\n    obj.save()\nincrement_vote.short_description = \"Increment the vote count by one\"\n```\n\nBy default, Django Object Actions will guess what to label the button\nbased on the name of the function. You can override this with a `label`\nattribute:\n\n```python\n@action(label=\"Vote++\")\ndef increment_vote(self, request, obj):\n    obj.votes = obj.votes + 1\n    obj.save()\n```\n\nor\n\n```python\ndef increment_vote(self, request, obj):\n    obj.votes = obj.votes + 1\n    obj.save()\nincrement_vote.label = \"Vote++\"\n```\n\nIf you need even more control, you can add arbitrary attributes to the buttons\nby adding a Django widget style\n[attrs](https://docs.djangoproject.com/en/stable/ref/forms/widgets/#django.forms.Widget.attrs)\nattribute:\n\n```python\n@action(attrs = {'class': 'addlink'})\ndef increment_vote(self, request, obj):\n    obj.votes = obj.votes + 1\n    obj.save()\n```\n\nor\n\n```python\ndef increment_vote(self, request, obj):\n    obj.votes = obj.votes + 1\n    obj.save()\nincrement_vote.attrs = {\n    'class': 'addlink',\n}\n```\n\n### Programmatically Disabling Actions\n\nYou can programmatically disable registered actions by defining your own\ncustom `get_change_actions()` method. In this example, certain actions\nonly apply to certain object states (e.g. You should not be able to\nclose an company account if the account is already closed):\n\n```python\ndef get_change_actions(self, request, object_id, form_url):\n    actions = super(PollAdmin, self).get_change_actions(request, object_id, form_url)\n    actions = list(actions)\n    if not request.user.is_superuser:\n        return []\n\n    obj = self.model.objects.get(pk=object_id)\n    if obj.question.endswith('?'):\n        actions.remove('question_mark')\n\n    return actions\n```\n\nThe same is true for changelist actions with `get_changelist_actions`.\n\n### Using POST instead of GET for actions\n\n⚠️ This is a beta feature and subject to change\n\nSince actions usually change data, for safety and semantics, it would be\npreferable that actions use a HTTP POST instead of a GET.\n\nYou can configure an action to only use POST with:\n\n```python\n@action(methods=(\"POST\",), button_type=\"form\")\n```\n\nOne caveat is Django's styling is pinned to anchor tags[^1], so to maintain\nvisual consistency, we have to use anchor tags and use JavaScript to make it act\nlike the submit button of the form.\n\n[^1]: https://github.com/django/django/blob/826ef006681eae1e9b4bd0e4f18fa13713025cba/django/contrib/admin/static/admin/css/base.css#L786\n\n### Alternate Installation\n\nYou don't have to add this to `INSTALLED_APPS`, all you need to to do\nis copy the template `django_object_actions/change_form.html` some place\nDjango's template loader [will find\nit](https://docs.djangoproject.com/en/stable/ref/settings/#template-dirs).\n\nIf you don't intend to use the template customizations at all, don't\nadd `django_object_actions` to your `INSTALLED_APPS` at all and use\n`BaseDjangoObjectActions` instead of `DjangoObjectActions`.\n\n## More Examples\n\nMaking an action that links off-site:\n\n```python\ndef external_link(self, request, obj):\n    from django.http import HttpResponseRedirect\n    return HttpResponseRedirect(f'https://example.com/{obj.id}')\n```\n\n## Limitations\n\n1.  `django-object-actions` expects functions to be methods of the model\n    admin. While Django gives you a lot more options for their admin\n    actions.\n2.  If you provide your own custom `change_form.html`, you'll also need\n    to manually copy in the relevant bits of [our change form\n    ](./django_object_actions/templates/django_object_actions/change_form.html).\n3.  Security. This has been written with the assumption that everyone in\n    the Django admin belongs there. Permissions should be enforced in\n    your own actions irregardless of what this provides. Better default\n    security is planned for the future.\n\n## Python and Django compatibility\n\nSee [`ci.yml`](./.github/workflows/ci.yml) for which Python and Django versions this supports.\n\n## Demo Admin \u0026 Docker images\n\nYou can try the demo admin against several versions of Django with these Docker\nimages: https://hub.docker.com/r/crccheck/django-object-actions/tags\n\nThis runs the example Django project in `./example_project` based on the \"polls\"\ntutorial. `admin.py` demos what you can do with this app.\n\n## Development\n\nGetting started:\n\n```shell\n# get a copy of the code\ngit clone git@github.com:crccheck/django-object-actions.git\ncd django-object-actions\n# Install requirements\nmake install\nmake test  # run test suite\nmake quickstart  # runs 'make resetdb' and some extra steps\n```\n\nVarious helpers are available as make commands. Type `make help` and\nview the `Makefile` to see what other things you can do.\n\n## Similar Packages\n\n[Django Modal Actions](https://github.com/Mng-dev-ai/django-modal-actions) can\nopen a simple form in a modal dialog.\n\nIf you want an actions menu for each row of your changelist, check out [Django\nAdmin Row Actions](https://github.com/DjangoAdminHackers/django-admin-row-actions).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrccheck%2Fdjango-object-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrccheck%2Fdjango-object-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrccheck%2Fdjango-object-actions/lists"}