Skip to content

Manager class

saffier.Manager

Manager(model_class=None)

Base Manager for the Saffier Models. To create a custom manager, the best approach is to inherit from the ModelManager.

Example

from saffier.managers import ModelManager from saffier.core.db.models import Model

class MyCustomManager(ModelManager): ...

class MyOtherManager(ModelManager): ...

class MyModel(saffier.Model): query = MyCustomManager() active = MyOtherManager()

...
PARAMETER DESCRIPTION
model_class

TYPE: Any DEFAULT: None

Source code in saffier/core/db/models/managers.py
32
33
def __init__(self, model_class: Any = None):
    self.model_class = model_class

model_class instance-attribute

model_class = model_class

__get__

__get__(_, owner)
PARAMETER DESCRIPTION
_

TYPE: Any

owner

TYPE: Any

Source code in saffier/core/db/models/managers.py
35
36
def __get__(self, _: Any, owner: Any) -> Type["QuerySet"]:
    return cast("Type[QuerySet]", self.__class__(model_class=owner))

get_queryset

get_queryset()

Returns the queryset object.

Checks for a global possible tenant and returns the corresponding queryset.

Source code in saffier/core/db/models/managers.py
38
39
40
41
42
43
44
45
46
47
48
def get_queryset(self) -> "QuerySet":
    """
    Returns the queryset object.

    Checks for a global possible tenant and returns the corresponding queryset.
    """
    tenant = get_tenant()
    if tenant:
        set_tenant(None)
        return QuerySet(self.model_class, table=self.model_class.table_schema(tenant))  # type: ignore
    return QuerySet(self.model_class)