Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
⏪️ Revert transferring class methods to metaclass
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Jul 10, 2024
1 parent 8bfac5a commit d576c4a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,17 @@ def __new__(cls, name, bases, attrs, **kwargs):
delattr(new_class, name)
return new_class

# def __dir__(cls):
# result = type.__dir__(cls)
# for attr in dir(cls):
# if not attr.startswith("__"):
# result.append(attr)
# return result

class Registry(models.Model, metaclass=RegistryMeta):
"""Registry base class.
Extends ``django.db.models.Model``.
Why does LaminDB call it `Registry` and not `Model`? The term "Registry" can't lead to
confusion with statistical, machine learning or biological models.
"""

@classmethod
def from_values(
cls,
values: ListLike,
Expand Down Expand Up @@ -581,6 +585,7 @@ def from_values(
"""
pass

@classmethod
def lookup(
cls,
field: StrField | None = None,
Expand Down Expand Up @@ -613,6 +618,7 @@ def lookup(
"""
pass

@classmethod
def filter(cls, **expressions) -> QuerySet:
"""Query records (see :doc:`meta`).
Expand All @@ -634,6 +640,7 @@ def filter(cls, **expressions) -> QuerySet:

return filter(cls, **expressions)

@classmethod
def get(cls, idlike: int | str) -> Registry:
"""Get a single record.
Expand Down Expand Up @@ -661,6 +668,7 @@ def get(cls, idlike: int | str) -> Registry:
else:
return qs.one()

@classmethod
def df(
cls, include: str | list[str] | None = None, join: str = "inner"
) -> pd.DataFrame:
Expand Down Expand Up @@ -688,6 +696,7 @@ def df(
query_set = query_set.order_by("-updated_at")
return query_set.df(include=include, join=join)

@classmethod
def search(
cls,
string: str,
Expand Down Expand Up @@ -719,6 +728,7 @@ def search(
"""
pass

@classmethod
def using(
cls,
instance: str,
Expand All @@ -738,11 +748,13 @@ def using(
"""
pass

@classmethod
def __get_schema_name__(cls) -> str:
schema_module_name = cls.__module__.split(".")[0]
schema_name = schema_module_name.replace("lnschema_", "")
return schema_name

@classmethod
def __get_name_with_schema__(cls) -> str:
schema_name = cls.__get_schema_name__()
if schema_name == "core":
Expand All @@ -751,16 +763,6 @@ def __get_name_with_schema__(cls) -> str:
schema_prefix = f"{schema_name}."
return f"{schema_prefix}{cls.__name__}"


class Registry(models.Model, metaclass=RegistryMeta):
"""Registry base class.
Extends ``django.db.models.Model``.
Why does LaminDB call it `Registry` and not `Model`? The term "Registry" can't lead to
confusion with statistical, machine learning or biological models.
"""

def save(self, *args, **kwargs) -> Registry:
"""Save.
Expand Down

0 comments on commit d576c4a

Please sign in to comment.