Skip to main content

Watch any object/field/relation of django and recive signals

Project description

Watch modification of any type of field in Django’s model and call registered callback function

Install

This library is on PyPI so you can install it with:

pip install django-observer

or from github:

pip install git+https://github.com/lambdalisue/django-observer.git

Usage

>>> from django.db import models
>>> from observer import watch
>>>
>>> class Entry(models.Model):
...     status = models.CharFiled('status', max_length=10)
...     body = models.CharField('title', max_length=100)
...
...     def save(self, *args, **kwargs):
...         super(Entry, self).save(*args, **kwargs)
...
...         # Watch callback, this is automatically called if `status` is **changed**
...         def watch_callback(sender, obj, attr):
...             # sender is a watcher instance
...             # obj is a instance of target
...             # attr is a name of target field
...             if obj.status == 'draft':
...                 obj.title = "draft - %s" % obj.body
...             else:
...                 obj.title = "publish - %s" % obj.body
...         # Start watching
...         self._watcher = watch(self, 'status', watch_callback)

See observer_test/src/miniblog/blog/tests/test_observer.py for more detail.

Settings

OBSERVER_DEFAULT_WATCHER

A class of watcher. Default is ‘observer.watcher.complex.ComplexWatcher’

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-observer-0.1rc3.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file django-observer-0.1rc3.tar.gz.

File metadata

File hashes

Hashes for django-observer-0.1rc3.tar.gz
Algorithm Hash digest
SHA256 b9342243059e7e68cbdd3bb8d825b92d03e31084308fc8dc9736824f94992912
MD5 f9707e1633e7e044b459fff70b2edab0
BLAKE2b-256 9985df8da018724953293dca213076fafa35efbc3a1c6e306a96dea20dc8c8d5

See more details on using hashes here.

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