xn-model 1.0.4__tar.gz → 1.0.6__tar.gz
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.
- {xn_model-1.0.4/xn_model.egg-info → xn_model-1.0.6}/PKG-INFO +1 -1
- {xn_model-1.0.4 → xn_model-1.0.6}/x_model/models.py +17 -7
- {xn_model-1.0.4 → xn_model-1.0.6/xn_model.egg-info}/PKG-INFO +1 -1
- {xn_model-1.0.4 → xn_model-1.0.6}/.env.sample +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/.gitignore +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/.pre-commit-config.yaml +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/README.md +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/makefile +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/pyproject.toml +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/setup.cfg +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/tests/__init__.py +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/tests/test_db.py +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/x_model/__init__.py +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/x_model/field.py +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/x_model/func.py +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/xn_model.egg-info/SOURCES.txt +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/xn_model.egg-info/dependency_links.txt +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/xn_model.egg-info/requires.txt +0 -0
- {xn_model-1.0.4 → xn_model-1.0.6}/xn_model.egg-info/top_level.txt +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
-
|
|
3
|
-
from
|
|
4
|
-
from tortoise import Model as BaseModel
|
|
2
|
+
from pydantic import ConfigDict, BaseModel
|
|
3
|
+
from tortoise import Model as TrtModel
|
|
5
4
|
from tortoise.contrib.pydantic import pydantic_model_creator, PydanticModel
|
|
6
5
|
from tortoise.fields import IntField
|
|
7
6
|
|
|
@@ -13,11 +12,19 @@ class TsTrait:
|
|
|
13
12
|
updated_at: datetime | None = DatetimeSecField(auto_now=True)
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
class
|
|
15
|
+
class PydIn(BaseModel):
|
|
16
|
+
_unq: list[str] = ["id"]
|
|
17
|
+
|
|
18
|
+
def df_unq(self) -> dict:
|
|
19
|
+
d = self.model_dump(exclude_none=True)
|
|
20
|
+
return {**{k: d.pop(k) for k in self._unq}, "defaults": d}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Model(TrtModel):
|
|
17
24
|
id: int = IntField(True)
|
|
18
25
|
|
|
19
26
|
_pyd: type[PydanticModel] = None # overridable
|
|
20
|
-
_pydIn: type[PydanticModel] = None # overridable
|
|
27
|
+
_pydIn: type[PydIn | PydanticModel] = None # overridable
|
|
21
28
|
_name: tuple[str] = ("name",)
|
|
22
29
|
_sorts: tuple[str] = ("-id",)
|
|
23
30
|
|
|
@@ -40,11 +47,14 @@ class Model(BaseModel):
|
|
|
40
47
|
|
|
41
48
|
# # # CRUD Methods # # #
|
|
42
49
|
@classmethod
|
|
43
|
-
async def get_one(cls, id_: int
|
|
44
|
-
if obj := await cls.get_or_none(id=id_
|
|
50
|
+
async def get_one(cls, id_: int) -> PydanticModel:
|
|
51
|
+
if obj := await cls.get_or_none(id=id_):
|
|
45
52
|
return await cls.pyd().from_tortoise_orm(obj)
|
|
46
53
|
raise LookupError(f"{cls.__name__}#{id_} not found")
|
|
47
54
|
|
|
55
|
+
async def one(self) -> PydanticModel:
|
|
56
|
+
return await self.pyd().from_tortoise_orm(self)
|
|
57
|
+
|
|
48
58
|
@classmethod
|
|
49
59
|
async def get_or_create_by_name(cls, name: str, attr_name: str = None, def_dict: dict = None) -> "Model":
|
|
50
60
|
attr_name = attr_name or list(cls._name)[0]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|