Skip to main content

One time method executor for Django models

Project description

One-time execution of Django model methods, when model instance meets specific conditions.

Examples

import datetime

from django.db import models
from django.db.models import Q
from terminator import execute_once


class Message(models.Model):
    sent = models.BooleanField(default=False)
    sender_email = models.EmailField()
    recipient_email = models.EmailField()
    subject = models.CharField(max_length=128)
    body = models.TextField()

    @execute_once(Q())
    def send(self):
        # Some code which sends the email…
        pass


class BirthdayGift(models.Model):
    birthday_date = models.DateField()

    @execute_once(lambda cls: Q(birthday_date__lte=datetime.date.today()))
    def send(self):
        # Some code which sends the gift…
        pass

Later:

from terminator import terminate

terminate()

For more extensive documentation, see the tests.

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

django-terminator-0.1.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

django_terminator-0.1.1-py27-none-any.whl (6.7 kB view hashes)

Uploaded Python 2.7

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page