From d576c4ad858b77666c268a57a1557acd2bb090d1 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Wed, 10 Jul 2024 15:42:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Revert=20transferring=20cl?= =?UTF-8?q?ass=20methods=20to=20metaclass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lnschema_core/models.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lnschema_core/models.py b/lnschema_core/models.py index dbf6244d..85b39a7f 100644 --- a/lnschema_core/models.py +++ b/lnschema_core/models.py @@ -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, @@ -581,6 +585,7 @@ def from_values( """ pass + @classmethod def lookup( cls, field: StrField | None = None, @@ -613,6 +618,7 @@ def lookup( """ pass + @classmethod def filter(cls, **expressions) -> QuerySet: """Query records (see :doc:`meta`). @@ -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. @@ -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: @@ -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, @@ -719,6 +728,7 @@ def search( """ pass + @classmethod def using( cls, instance: str, @@ -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": @@ -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.