observer package

Submodules

observer.compat module

observer.compat.lru_cache(maxsize)[source]

observer.conf module

observer.decorators module

observer.decorators.watch(attr, callback, **kwargs)[source]

A decorator function for watching model attribute

observer.investigator module

class observer.investigator.Investigator(model, include=None, exclude=None)[source]

Bases: object

A model modification investigator

Create an instance of investigator with a model class and call ‘prepare’ method just before save the model. After the model is saved, call ‘investigate’ method and the method will yields the field names modified.

get_cached(pk, ignore_exception=True)[source]

Get cached object

Parameters:
  • pk (any) – A primary key of the object
  • ignore_exception (bool) – Return None if the object is not found, if this is False, ObjectDoesNotExist raised
Raises:

ObjectDoesNotExist – When a specified object does not exists in the cache and ignore_exception is False.

Returns:

object or None

get_object(pk, ignore_exception=True)[source]

Get latest object

It try to get the latest (unsaved) object from the database. If ignore_exception is True, return None, otherwise it raise ObjectDoesNotExist exception when no object is found.

Parameters:
  • pk (any) – A primary key of the object
  • ignore_exception (bool) – Return None if the object is not found. if this is False, ObjectDoesNotExist raised.
Raises:

ObjectDoesNotExist – When a specified object does not exists ignore_exception is False.

Returns:

object or None

investigate(instance)[source]

Call this function after the model instance is saved. It yield a name of modified attributes

prepare(instance)[source]

Call this function before save the model instance

observer.models module

observer.shortcuts module

observer.shortcuts.watch(model, attr, callback, **kwargs)[source]

A shortcut function for watching model attribute

Module contents