Package

Level clause

pgtrigger.Row = <pgtrigger.core._Level object>
pgtrigger.Statement = <pgtrigger.core._Level object>

When clause

pgtrigger.After = <pgtrigger.core._When object>
pgtrigger.Before = <pgtrigger.core._When object>
pgtrigger.InsteadOf = <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

alias of <pgtrigger.core._Operation object>

class pgtrigger.UpdateOf(*columns)[source]

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

Referencing clause

class pgtrigger.Referencing(*, old=None, new=None)[source]

For specifying the REFERENCING construct of a statement-level 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(*, name=None, level=None, when=None, operation=None, condition=None, referencing=None, func=None, declare=None)[source]

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

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

A trigger that raises an exception

class pgtrigger.SoftDelete(*, name=None, condition=None, field=None, value=<object object>)[source]

Sets a field to a value when a delete happens.

Supply the trigger with the “field” that will be set upon deletion and the “value” to which it should be set. The “value” defaults to False.

Note

This trigger currently only supports nullable BooleanField, CharField, and IntField fields.

class pgtrigger.FSM(*, name=None, condition=None, field=None, transitions=None)[source]

Enforces a finite state machine on a field.

Supply the trigger with the “field” that transitions and then a list of tuples of valid transitions to the “transitions” argument.

Note

Only non-null CharField fields are currently supported.

Management

pgtrigger.get(*uris, database=None)[source]

Get triggers matching URIs or all triggers registered to models. If a database is provided, will only enable triggers registered to a particular database.

A URI is in the format of “app_label.model_name:trigger_name”

pgtrigger.install(*uris, database=None)[source]

Install registered triggers matching URIs or all triggers if URIs aren’t provided. If URIs aren’t provided, prune any orphaned triggers from the database. If a database is provided, will only install triggers registered to a particular database.

pgtrigger.uninstall(*uris, database=None)[source]

Uninstalls registered triggers matching URIs or all triggers if no URIs are provided. If no URIs are provided, will also try to prune any lingering triggers that are no longer in the code base.

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

If a database is provided, will only uninstall triggers registered to a particular database.

pgtrigger.enable(*uris, database=None)[source]

Enables registered triggers matching URIs or all triggers if no URIs are provided. If a database is provided, will only enable triggers registered to a particular database.

pgtrigger.disable(*uris, database=None)[source]

Disables registered triggers matching URIs or all triggers if no URIs are provided. If a database is provided, will only disable triggers registered to a particular database.

pgtrigger.prune(database=None)[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

Parameters

database (str, default=None) – Only prune triggers from this database. Defaults to returning results from all databases

pgtrigger.ignore(*uris)[source]

Dynamically ignore registered triggers matching URIs from executing in an individual thread. If no URIs are provided, ignore all pgtriggers from executing in an individual thread.