# django-admin-form-action [![Latest Version][latest-version-image]][latest-version-link]
[![Test Status][test-status-image]][test-status-link]
[![codecov][codecov-image]][codecov-link]
[![Python Support][python-support-image]][python-support-link]
`django-admin-form-action` is intended to implement parametrized actions on the Django admin site.
Action parameters are passed through an intermediate form as it shown below.
![demo](https://github.com/pauk-slon/django-admin-form-action/assets/2351932/a6c67b47-0fde-4d9e-9c23-cb50e9a87e48)
The demonstrated functionality can be implemented with `django-admin-form-action` in the following way:
```python
from django import forms
from django.contrib import admin
from django.contrib.auth.models import Group, User
from admin_form_action import form_action
class GroupsForm(forms.Form):
groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all())
def add_user(self, user: User):
user.groups.add(*self.cleaned_data['groups'])
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
actions = ['add_to_groups']
@form_action(GroupsForm)
@admin.action(description='Add selected users to certain groups')
def add_to_groups(self, request, queryset):
# Validated form is injected by `@form_action` to `request.form`
groups_form = request.form
for user in queryset:
groups_form.add_user(user)
```
## Install
```shell
pip install django-admin-form-action
```
```python
INSTALLED_APPS = [
...
'admin_form_action',
...
]
```
## Development
### Run demo app
```shell
poetry install
poetry run django-admin migrate --settings=tests.app.settings
poetry run django-admin runserver --settings=tests.app.settings
```
### Test
```shell
poetry run pytest
```
### Lint
```shell
poetry run isort .
poetry run ruff .
poetry run mypy .
```
[latest-version-image]: https://img.shields.io/pypi/v/django-admin-form-action.svg
[latest-version-link]: https://pypi.org/project/django-admin-form-action/
[codecov-image]: https://codecov.io/gh/pauk-slon/django-admin-form-action/graph/badge.svg?token=QCY3CW2ZVG
[codecov-link]: https://codecov.io/gh/pauk-slon/django-admin-form-action
[test-status-image]: https://github.com/pauk-slon/django-admin-form-action/actions/workflows/test.yaml/badge.svg
[test-status-link]: https://github.com/pauk-slon/django-admin-form-action/actions/workflows/test.yaml
[python-support-image]: https://img.shields.io/pypi/pyversions/django-admin-form-action.svg
[python-support-link]: https://pypi.org/project/django-admin-form-action/
Raw data
{
"_id": null,
"home_page": "https://github.com/pauk-slon/django-admin-form-action",
"name": "django-admin-form-action",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "django,admin,action",
"author": "Dmitry Kolyagin",
"author_email": "dmitry.kolyagin@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/93/17/052f899c7270e4340c5bc550f611aadec4f92e20febf695f5b16237a0354/django_admin_form_action-1.0.0.tar.gz",
"platform": null,
"description": "# django-admin-form-action [![Latest Version][latest-version-image]][latest-version-link]\n\n[![Test Status][test-status-image]][test-status-link]\n[![codecov][codecov-image]][codecov-link]\n[![Python Support][python-support-image]][python-support-link]\n\n`django-admin-form-action` is intended to implement parametrized actions on the Django admin site. \nAction parameters are passed through an intermediate form as it shown below.\n\n![demo](https://github.com/pauk-slon/django-admin-form-action/assets/2351932/a6c67b47-0fde-4d9e-9c23-cb50e9a87e48)\n\nThe demonstrated functionality can be implemented with `django-admin-form-action` in the following way:\n\n```python\nfrom django import forms\nfrom django.contrib import admin\nfrom django.contrib.auth.models import Group, User\n\nfrom admin_form_action import form_action\n\n\nclass GroupsForm(forms.Form):\n groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all())\n\n def add_user(self, user: User):\n user.groups.add(*self.cleaned_data['groups'])\n\n@admin.register(User)\nclass UserAdmin(admin.ModelAdmin):\n actions = ['add_to_groups']\n\n @form_action(GroupsForm)\n @admin.action(description='Add selected users to certain groups')\n def add_to_groups(self, request, queryset):\n # Validated form is injected by `@form_action` to `request.form`\n groups_form = request.form\n for user in queryset:\n groups_form.add_user(user)\n```\n\n## Install\n\n```shell\npip install django-admin-form-action\n```\n\n```python\nINSTALLED_APPS = [\n ...\n 'admin_form_action',\n ...\n]\n```\n\n## Development\n\n### Run demo app\n\n```shell\npoetry install\npoetry run django-admin migrate --settings=tests.app.settings\npoetry run django-admin runserver --settings=tests.app.settings\n```\n\n### Test\n\n```shell\npoetry run pytest\n```\n\n### Lint\n\n```shell\npoetry run isort .\npoetry run ruff . \npoetry run mypy .\n```\n\n[latest-version-image]: https://img.shields.io/pypi/v/django-admin-form-action.svg\n[latest-version-link]: https://pypi.org/project/django-admin-form-action/\n[codecov-image]: https://codecov.io/gh/pauk-slon/django-admin-form-action/graph/badge.svg?token=QCY3CW2ZVG\n[codecov-link]: https://codecov.io/gh/pauk-slon/django-admin-form-action\n[test-status-image]: https://github.com/pauk-slon/django-admin-form-action/actions/workflows/test.yaml/badge.svg\n[test-status-link]: https://github.com/pauk-slon/django-admin-form-action/actions/workflows/test.yaml\n[python-support-image]: https://img.shields.io/pypi/pyversions/django-admin-form-action.svg\n[python-support-link]: https://pypi.org/project/django-admin-form-action/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Parametrized actions for Django admin site",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/pauk-slon/django-admin-form-action",
"Repository": "https://github.com/pauk-slon/django-admin-form-action"
},
"split_keywords": [
"django",
"admin",
"action"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5e0319fd780fdb010918dbcf54086c425a0f1a78c3e456ac9d83ef63a8eb9a0b",
"md5": "b311dcf87a25375c16a318fd4652c75b",
"sha256": "6df55b83b8ff1f4d2069abdea9823c9475195c411711ff3a51bba9e09e492e70"
},
"downloads": -1,
"filename": "django_admin_form_action-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b311dcf87a25375c16a318fd4652c75b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 5173,
"upload_time": "2023-10-08T15:48:50",
"upload_time_iso_8601": "2023-10-08T15:48:50.566258Z",
"url": "https://files.pythonhosted.org/packages/5e/03/19fd780fdb010918dbcf54086c425a0f1a78c3e456ac9d83ef63a8eb9a0b/django_admin_form_action-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9317052f899c7270e4340c5bc550f611aadec4f92e20febf695f5b16237a0354",
"md5": "1a235d0e8bac8f5fbdb155dd9bad05e2",
"sha256": "3849d9976daf47aa60f02c5eb273932bfbcdaa1bcfd024a9ecb0b383ad643e3e"
},
"downloads": -1,
"filename": "django_admin_form_action-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "1a235d0e8bac8f5fbdb155dd9bad05e2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 4369,
"upload_time": "2023-10-08T15:48:52",
"upload_time_iso_8601": "2023-10-08T15:48:52.068391Z",
"url": "https://files.pythonhosted.org/packages/93/17/052f899c7270e4340c5bc550f611aadec4f92e20febf695f5b16237a0354/django_admin_form_action-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-08 15:48:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pauk-slon",
"github_project": "django-admin-form-action",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-admin-form-action"
}