xn-model 1.0.7__py3-none-any.whl → 1.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
x_model/models.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from datetime import datetime
2
+ from typing import Self
2
3
 
3
4
  from pydantic import ConfigDict, BaseModel
4
5
  from tortoise import Model as TortModel
@@ -16,8 +17,8 @@ class TsTrait:
16
17
  class Model(TortModel):
17
18
  id: int = IntField(True)
18
19
 
19
- _out: type[BaseModel] = None # overridable
20
- _in: type[BaseModel] = None # overridable
20
+ _out_type: type[BaseModel] = None # overridable
21
+ _in_type: type[BaseModel] = None # overridable
21
22
  _name: tuple[str] = ("name",)
22
23
  _sorts: tuple[str] = ("-id",)
23
24
 
@@ -25,31 +26,31 @@ class Model(TortModel):
25
26
  return sep.join(getattr(self, name_fragment) for name_fragment in self._name)
26
27
 
27
28
  @classmethod
28
- def pyd(cls):
29
- if not cls._out:
30
- cls._out = pydantic_model_creator(cls, name=cls.__name__ + "Out")
31
- return cls._out
29
+ def out_type(cls):
30
+ if not cls._out_type:
31
+ cls._out_type = pydantic_model_creator(cls, name=cls.__name__ + "Out")
32
+ return cls._out_type
32
33
 
33
34
  @classmethod
34
- def pyd_in(cls):
35
- if not cls._in:
36
- cls._in = pydantic_model_creator(
35
+ def in_type(cls):
36
+ if not cls._in_type:
37
+ cls._in_type = pydantic_model_creator(
37
38
  cls, name=cls.__name__ + "In", exclude_readonly=True, meta_override=cls.PydanticMetaIn
38
39
  )
39
- return cls._in
40
+ return cls._in_type
40
41
 
41
42
  # # # CRUD Methods # # #
42
43
  @classmethod
43
44
  async def get_one(cls, id_: int) -> PydanticModel:
44
45
  if obj := await cls.get_or_none(id=id_):
45
- return await cls.pyd().from_tortoise_orm(obj)
46
+ return await cls.out_type().from_tortoise_orm(obj)
46
47
  raise LookupError(f"{cls.__name__}#{id_} not found")
47
48
 
48
49
  async def one(self) -> PydanticModel:
49
- return await self.pyd().from_tortoise_orm(self)
50
+ return await self.out_type().from_tortoise_orm(self)
50
51
 
51
52
  @classmethod
52
- async def get_or_create_by_name(cls, name: str, attr_name: str = None, def_dict: dict = None) -> "Model":
53
+ async def get_or_create_by_name(cls, name: str, attr_name: str = None, def_dict: dict = None) -> Self:
53
54
  attr_name = attr_name or list(cls._name)[0]
54
55
  if not (obj := await cls.get_or_none(**{attr_name: name})):
55
56
  next_id = (await cls.all().order_by("-id").first()).id + 1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xn-model
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -1,9 +1,9 @@
1
1
  x_model/__init__.py,sha256=JRsYD3P-8pHpEkCUgy6GuodkT7ZaY1AEeEK1CbpgZw4,428
2
2
  x_model/field.py,sha256=w5BAoNA33a-uROaExx5Pr3jYQnUMKIYFYcPTjdBlx3M,2784
3
3
  x_model/func.py,sha256=E7jDoHJGaFpKvxbHnT_lyBxUZeMo-GRd5gv9dLw7B9s,289
4
- x_model/models.py,sha256=xalrke04TUv-pmzXwOir-naUREcBjaOXiOWQkUuj4Ic,2633
4
+ x_model/models.py,sha256=-dhEPBoOIcMvkWayjgOBt9xYiOalv8ZIM9bmFziVdzM,2710
5
5
  x_model/types.py,sha256=m7B5XOQvXpOMe8GpO0IizmQLAMd-UzMa9t0hodnfCXw,301
6
- xn_model-1.0.7.dist-info/METADATA,sha256=UaOx1foFPLlj651w2uf1yp1su-0cYJ8tm4Ipl0wndHo,961
7
- xn_model-1.0.7.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
8
- xn_model-1.0.7.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
9
- xn_model-1.0.7.dist-info/RECORD,,
6
+ xn_model-1.0.9.dist-info/METADATA,sha256=T5WCjgQpW4Jp-TH2rwqBmXO7N3dy3felQZ9_AJxbSe8,961
7
+ xn_model-1.0.9.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
8
+ xn_model-1.0.9.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
9
+ xn_model-1.0.9.dist-info/RECORD,,