Skip to main content

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

Project description

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

This observer can watch

  • Any value type of field (CharField, IntegerField …)
  • Any Model type of field (ForeignKey, OneToOneField, GenericForeignKey)
  • Any RelatedManager type of field (field automatically created via related_name of ForeignKey)
  • Any ManyRelatedManager type of field (ManyToManyField)
  • Any GenericRelatedObjectManager type of field (GenericRelation)
  • Any Model instance


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

pip install django-observer

or from github:

pip install git+


>>> 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/ for more detail.


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.

Files for django-observer, version 0.4.3
Filename, size File type Python version Upload date Hashes
Filename, size django-observer-0.4.3.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page