Skip to content

Manager class

edgy.Manager

Manager(*, owner=None, inherit=True, name='', instance=None)

Bases: BaseManager

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

Example

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


class MyCustomManager(ModelManager): ...


class MyOtherManager(ModelManager): ...


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

    ...
PARAMETER DESCRIPTION
owner

TYPE: Optional[Union[type[BaseModelType]]] DEFAULT: None

inherit

TYPE: bool DEFAULT: True

name

TYPE: str DEFAULT: ''

instance

TYPE: Optional[Union[BaseModelType]] DEFAULT: None

Source code in edgy/core/db/models/managers.py
11
12
13
14
15
16
17
18
19
20
21
22
def __init__(
    self,
    *,
    owner: Optional[Union[type["BaseModelType"]]] = None,
    inherit: bool = True,
    name: str = "",
    instance: Optional[Union["BaseModelType"]] = None,
):
    self.owner = owner
    self.inherit = inherit
    self.name = name
    self.instance = instance

owner instance-attribute

owner = owner

inherit instance-attribute

inherit = inherit

name instance-attribute

name = name

instance instance-attribute

instance = instance

model_class property

model_class

get_queryset

get_queryset()

Returns the queryset object.

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

Source code in edgy/core/db/models/managers.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def get_queryset(self) -> "QuerySet":
    """
    Returns the queryset object.

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