Reference
Models
TenantModel
- class django_pgschemas.models.TenantModel(*args, **kwargs)
All tenant models must inherit this class.
- auto_create_schema = True
Set this flag to
False
on a parent class if you don’t want the schema to be automatically created upon save.
- auto_drop_schema = False
USE THIS WITH CAUTION! Set this flag to
True
on a parent class if you want the schema to be automatically deleted if the tenant row gets deleted.
- create_schema(sync_schema: bool = True, verbosity: int = 1) bool
Creates or clones the schema
schema_name
for this tenant.
- drop_schema() bool
Drops the schema.
DomainModel
Utils
- django_pgschemas.utils.check_schema_name(name: str) None
Checks schema name and raises
ValidationError
ifname
is not a valid identifier.
- django_pgschemas.utils.create_or_clone_schema(schema_name: str, sync_schema: bool = True, verbosity: int = 1) bool
Creates the schema
schema_name
. Optionally checks if the schema already exists before creating it. ReturnsTrue
if the schema was created,False
otherwise.
- django_pgschemas.utils.get_domain_model(require_ready: bool = True) Model | None
Returns the domain model.
- django_pgschemas.utils.get_tenant_model(require_ready: bool = True) Model | None
Returns the tenant model.
- django_pgschemas.utils.is_valid_identifier(identifier: str) bool
Checks the validity of identifier.
- django_pgschemas.utils.is_valid_schema_name(name: str) bool
Checks the validity of a schema name.
- django_pgschemas.utils.run_in_public_schema(func: Callable) Callable
Decorator that makes decorated function to be run in the public schema.
- django_pgschemas.utils.schema_exists(schema_name: str) bool
Checks if a schema exists in database.
Signals
- django_pgschemas.signals.schema_activate = <django.dispatch.dispatcher.Signal object>
Sent after a schema has been activated
- django_pgschemas.signals.dynamic_tenant_needs_sync = <django.dispatch.dispatcher.Signal object>
Sent when a schema from a dynamic tenant needs to be synced
- django_pgschemas.signals.dynamic_tenant_post_sync = <django.dispatch.dispatcher.Signal object>
Sent after a tenant has been saved, its schema created and synced
- django_pgschemas.signals.dynamic_tenant_pre_drop = <django.dispatch.dispatcher.Signal object>
Sent when a schema from a dynamic tenant is about to be dropped
URL resolvers
- django_pgschemas.routing.urlresolvers.get_urlconf_from_schema(schema: Schema) str | None
Returns the proper URLConf depending on the schema.