Extension for the Django admin panel that makes it possible to add actions that do not require a queryset to run.
Project description
django-no-queryset-admin-actions
Extension for the Django admin panel that makes it possible to add actions that do not require a queryset to run.
Works with django-admin-action-forms.
🔌 Installation
-
Install using
pip:$ pip3 install django-no-queryset-admin-actions
-
Add
'django_no_queryset_admin_actions'to yourINSTALLED_APPSsetting.INSTALLED_APPS = [ ... 'django_no_queryset_admin_actions', ]
✏️ Examples
No queryset actions
Let's say you have an action that fetches external orders from an API. You don't need a queryset to run this action,
but Django requires it by default. By using the @no_queryset_action, you can bypass that, and create actions that can
be run without selecting any objects.
from django.contrib.admin import ModelAdmin, register
from django_no_queryset_admin_actions import NoQuerySetAdminActionsMixin, no_queryset_action
@register(ExternalOrder)
class ExternalOrderAdmin(NoQuerySetAdminActionsMixin, ModelAdmin):
@no_queryset_action(description="Fetch external orders")
def fetch_external_orders(self, request): # <- No `queryset` parameter
...
actions = [fetch_external_orders]
Optional queryset actions
Another use case is when you have an action that can be run on a specific queryset, but you also want to allow running it without selecting any objects.
This type of action could be used to e.g.:
- default to all, or a filtered subset of objects when no selection is made
- choose a random object if no specific item is selected
Leveraging the @optional_queryset_action decorator, you can create actions that run whether or not objects are selected.
Let's say, that ExternalOrder objects fetched in the previous example may sometimes need updating. In this example, if no objects are selected, queryset will be empty, and the action will default to updating all ExternalOrder objects.
from django.contrib.admin import ModelAdmin, register
from django_no_queryset_admin_actions import NoQuerySetAdminActionsMixin, optional_queryset_action
@register(ExternalOrder)
class ExternalOrderAdmin(NoQuerySetAdminActionsMixin, ModelAdmin):
@optional_queryset_action(description="Update external orders")
def update_external_orders(self, request, queryset): # <- `queryset` can be empty
if not queryset:
queryset = ExternalOrder.objects.all()
...
actions = [update_external_orders]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_no_queryset_admin_actions-1.2.1.tar.gz.
File metadata
- Download URL: django_no_queryset_admin_actions-1.2.1.tar.gz
- Upload date:
- Size: 627.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8db49d4a6ad98b424a906a71754afcc73904050b5f2758a8ce44bc2498a2a82c
|
|
| MD5 |
ec6ed0e295684167b51fc1ba712ead4c
|
|
| BLAKE2b-256 |
e066d11866bacc4eb4138d0616352a5eceb4ac4a027b2abb74a6030e26fdeba5
|
Provenance
The following attestation bundles were made for django_no_queryset_admin_actions-1.2.1.tar.gz:
Publisher:
publish-to-pypi.yaml on michalpokusa/django-no-queryset-admin-actions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_no_queryset_admin_actions-1.2.1.tar.gz -
Subject digest:
8db49d4a6ad98b424a906a71754afcc73904050b5f2758a8ce44bc2498a2a82c - Sigstore transparency entry: 650621265
- Sigstore integration time:
-
Permalink:
michalpokusa/django-no-queryset-admin-actions@5eb426ad57b47b2460b9e09fd65f07a862a7ecd3 -
Branch / Tag:
refs/tags/1.2.1 - Owner: https://github.com/michalpokusa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yaml@5eb426ad57b47b2460b9e09fd65f07a862a7ecd3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_no_queryset_admin_actions-1.2.1-py3-none-any.whl.
File metadata
- Download URL: django_no_queryset_admin_actions-1.2.1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d962808eb8a50013137fd198edf951ce8a6c55dc5bbd34a57a000a7f0d1bff7d
|
|
| MD5 |
71f96a0370c3a209aba0cead39f6cd41
|
|
| BLAKE2b-256 |
c31fcab1f8f93eb75d0bd3c228ec62f4831d8e410cc433afec0ebbd15a869244
|
Provenance
The following attestation bundles were made for django_no_queryset_admin_actions-1.2.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yaml on michalpokusa/django-no-queryset-admin-actions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_no_queryset_admin_actions-1.2.1-py3-none-any.whl -
Subject digest:
d962808eb8a50013137fd198edf951ce8a6c55dc5bbd34a57a000a7f0d1bff7d - Sigstore transparency entry: 650621293
- Sigstore integration time:
-
Permalink:
michalpokusa/django-no-queryset-admin-actions@5eb426ad57b47b2460b9e09fd65f07a862a7ecd3 -
Branch / Tag:
refs/tags/1.2.1 - Owner: https://github.com/michalpokusa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yaml@5eb426ad57b47b2460b9e09fd65f07a862a7ecd3 -
Trigger Event:
push
-
Statement type: