# Reference

## Models

### `TenantMixin`

class django_pgschemas.models.TenantMixin(*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=True, verbosity=1)

    Creates or clones the schema `schema_name` for this tenant.

  drop_schema()

    Drops the schema.

### `DomainMixin`

class django_pgschemas.models.DomainMixin(*args, **kwargs)

  All models that store the domains must inherit this class.

  absolute_url(path)

    Constructs an absolute url for this domain / folder and a given path

## Utils

django_pgschemas.utils.check_schema_name(name: str)

  Checks schema name and raises `ValidationError` if `name` 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. Returns `True` 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.remove_www(hostname: str) → str

  Removes `www`. from the beginning of the address. Only for routing purposes. `www.test.com/login/` and `test.com/login/` should find the same tenant.

django_pgschemas.utils.run_in_public_schema(func)

  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.urlresolvers.get_urlconf_from_schema(schema)

  Returns the proper URLConf depending on the schema. The schema must come with `domain_url` and `folder` members set.