Skip to content

Latest commit

 

History

History
64 lines (41 loc) · 1.92 KB

File metadata and controls

64 lines (41 loc) · 1.92 KB

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.

It does one thing and one thing only.

🔌 Installation

  1. Install using pip:

    $ pip3 install django-no-queryset-admin-actions
  2. Add 'django_no_queryset_admin_actions' to your INSTALLED_APPS setting.

    INSTALLED_APPS = [
        ...
        'django_no_queryset_admin_actions',
    ]

✏️ Example

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 this extension, you can bypass that, and create actions that can be run without selecting any objects.

from django.contrib.admin import ModelAdmin, register, action

from django_no_queryset_admin_actions import NoQuerySetAdminActionsMixin


@register(ExternalOrder)
class ExternalOrderAdmin(NoQuerySetAdminActionsMixin, ModelAdmin):

    ...

    @action(description="Fetch external orders")
    def fetch_external_orders(self, request): # <- No `queryset` parameter
        ...

    actions = ["fetch_external_orders"]

    no_queryset_actions = ["fetch_external_orders"]