django-model-event-actions Latest version on PyPI

Python version Django versions Pypi link Software license

This package is a replacement for the builtin Django Signals which you can define all of the events and actions in the model itself and add conditions to determine when they are triggered. With the help of this package you can track the changed field previous and current values and determine when an action should trigger by creating an event with the decorators in the model.

A simple example will be:

class User(EventActionModel):
    is_active = models.BooleanField()

    @PostSaveEvent(field='is_active', prev=False, now=True)
    def user_deactivated(self):
        # logic

    @PostCreateEvent()
    def post_create(self):
        # logic

Installation

Get the package from pypi:

$ pip install django-model-event-actions

Subclass the models:

from django_model_event_actions.models import EventActionModel

class MyClass(EventActionModel):
    ...

Add the event decorator:

from django_model_event_actions.models import EventActionModel

class MyClass(EventActionModel):
    name = models.CharField()

    @PostCreateEvent(field='name'):
    def my_handler(self):
        # logic

Tutorial

To start using the package take a look at the documentation in readthedocs.