Package

When clause

pgtrigger.After = <pgtrigger.core._When object>
pgtrigger.Before = <pgtrigger.core._When object>

Operation clause

pgtrigger.Truncate = <pgtrigger.core._Operation object>
pgtrigger.Delete = <pgtrigger.core._Operation object>
pgtrigger.Insert = <pgtrigger.core._Operation object>
pgtrigger.Update
class pgtrigger.UpdateOf(*columns)[source]

For specifying “UPDATE OF” in the “operation” clause of a trigger

Conditions

class pgtrigger.Condition(sql=None)[source]

For specifying free-form SQL in the “condition” clause of a trigger

class pgtrigger.Q(*args, _connector=None, _negated=False, **kwargs)[source]

Similar to Django’s Q object, allows referencing the old and new rows in a trigger condition.

class pgtrigger.F(*args, **kwargs)[source]

Similar to Django’s F object, allows referencing the old and new rows in a trigger condition.

class pgtrigger.IsDistinctFrom(lhs, rhs)[source]

A custom IS DISTINCT FROM field lookup for common trigger conditions

class pgtrigger.IsNotDistinctFrom(lhs, rhs)[source]

A custom IS NOT DISTINCT FROM field lookup for common trigger conditions

Triggers

pgtrigger.register(*triggers)[source]

Register the given triggers with wrapped Model class

class pgtrigger.Trigger(*, when=None, operation=None, condition=None, func=None)[source]

For specifying a free-form PL/pgSQL trigger function or for creating derived trigger classes.

class pgtrigger.Protect(*, when=None, operation=None, condition=None, func=None)[source]

A trigger that raises an exception

class pgtrigger.SoftDelete(*, condition=None, field=None)[source]

Sets a field to “False” when a delete happens

Management

pgtrigger.get()[source]

Get all triggers registered to models

Note: Triggers can also be added to models with the pgtrigger.config decorator

pgtrigger.install()[source]

Install all triggers registered to models

pgtrigger.uninstall()[source]

Uninstalls all registered triggers.

Running migrations will re-install any existing triggers. This behavior is overridable with settings.PGTRIGGER_INSTALL_ON_MIGRATE

Note: This will not uninstall triggers when deleting a model. This operation is performed by the “prune” command.

pgtrigger.enable()[source]

Enables all registered triggers

pgtrigger.disable()[source]

Disables all registered triggers

pgtrigger.prune()[source]

Remove any pgtrigger triggers in the database that are not used by models. I.e. if a model or trigger definition is deleted from a model, ensure it is removed from the database