Skip to content

Signals

django-adminactions provides the following signals:

adminaction_requested

Sent when the action is requested (ie click 'Go' in the admin changelist view). The handler can raise a :ref:actioninterrupted to interrupt the action's execution. The handler can rely on the following parameter:

Example::

from adminactions.exceptions import ActionInterrupted
from adminactions.signals import adminaction_requested

def myhandler(sender, action, request, queryset, modeladmin, **kwargs):
    if action == 'mass_update' and queryset.filter(locked==True).exists():
        raise ActionInterrupted('Queryset cannot contains locked records')

adminaction_requested.connect(myhandler, sender=MyModel, action='mass_update`)

adminaction_start

Sent after the form has been validated (ie click 'Apply' in the action Form), just before the execution of the action. The handler can raise a :ref:actioninterrupted to avoid the stop execution. The handler can rely on the following parameter:

Example

from adminactions.signals import adminaction_start

def myhandler(sender, action, request, queryset, modeladmin, form, **kwargs):
    if action == 'export' and 'money' in form.cleaned_data['columns']:
        if not request.user.is_administrator:
            raise ActionInterrupted('Only administrors can export `money` field')

adminaction_start.connect(myhandler, sender=MyModel, action='export`)

adminaction_end

Sent after the successfully execution of the action. The handler can rely on the following parameter:

mass_update_process

Sent before the record is updated: The handler can rely on the following parameter:

Es:

from django.contrib.auth.models import User
from django.dispatch import receiver
from adminactions.signals import mass_update_process
from adminactions.exceptions import MassUpdateSkipRecordError


@receiver(mass_update_process, sender=User)
def my_handler(sender, record: User, **kwargs):
    if record.is_superuser:
        raise MassUpdateSkipRecordError