xn-model 1.0.6__py3-none-any.whl → 1.0.7__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 +13 -20
- x_model/types.py +15 -0
- {xn_model-1.0.6.dist-info → xn_model-1.0.7.dist-info}/METADATA +1 -1
- xn_model-1.0.7.dist-info/RECORD +9 -0
- {xn_model-1.0.6.dist-info → xn_model-1.0.7.dist-info}/WHEEL +1 -1
- xn_model-1.0.6.dist-info/RECORD +0 -8
- {xn_model-1.0.6.dist-info → xn_model-1.0.7.dist-info}/top_level.txt +0 -0
x_model/models.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
|
|
2
3
|
from pydantic import ConfigDict, BaseModel
|
|
3
|
-
from tortoise import Model as
|
|
4
|
+
from tortoise import Model as TortModel
|
|
4
5
|
from tortoise.contrib.pydantic import pydantic_model_creator, PydanticModel
|
|
5
6
|
from tortoise.fields import IntField
|
|
6
7
|
|
|
@@ -12,38 +13,30 @@ class TsTrait:
|
|
|
12
13
|
updated_at: datetime | None = DatetimeSecField(auto_now=True)
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
class
|
|
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):
|
|
16
|
+
class Model(TortModel):
|
|
24
17
|
id: int = IntField(True)
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
_out: type[BaseModel] = None # overridable
|
|
20
|
+
_in: type[BaseModel] = None # overridable
|
|
28
21
|
_name: tuple[str] = ("name",)
|
|
29
22
|
_sorts: tuple[str] = ("-id",)
|
|
30
23
|
|
|
31
|
-
def
|
|
32
|
-
return
|
|
24
|
+
def __repr__(self, sep: str = " ") -> str:
|
|
25
|
+
return sep.join(getattr(self, name_fragment) for name_fragment in self._name)
|
|
33
26
|
|
|
34
27
|
@classmethod
|
|
35
28
|
def pyd(cls):
|
|
36
|
-
if not cls.
|
|
37
|
-
cls.
|
|
38
|
-
return cls.
|
|
29
|
+
if not cls._out:
|
|
30
|
+
cls._out = pydantic_model_creator(cls, name=cls.__name__ + "Out")
|
|
31
|
+
return cls._out
|
|
39
32
|
|
|
40
33
|
@classmethod
|
|
41
34
|
def pyd_in(cls):
|
|
42
|
-
if not cls.
|
|
43
|
-
cls.
|
|
35
|
+
if not cls._in:
|
|
36
|
+
cls._in = pydantic_model_creator(
|
|
44
37
|
cls, name=cls.__name__ + "In", exclude_readonly=True, meta_override=cls.PydanticMetaIn
|
|
45
38
|
)
|
|
46
|
-
return cls.
|
|
39
|
+
return cls._in
|
|
47
40
|
|
|
48
41
|
# # # CRUD Methods # # #
|
|
49
42
|
@classmethod
|
x_model/types.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class New(BaseModel):
|
|
5
|
+
_unq: list[str] = []
|
|
6
|
+
|
|
7
|
+
def df_unq(self) -> dict:
|
|
8
|
+
d = self.model_dump(exclude_none=True)
|
|
9
|
+
return {**{k: d.pop(k) for k in set(self._unq) & d.keys()}, "defaults": d}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Upd(New):
|
|
13
|
+
_unq: list[str] = ["id"]
|
|
14
|
+
|
|
15
|
+
id: int
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
x_model/__init__.py,sha256=JRsYD3P-8pHpEkCUgy6GuodkT7ZaY1AEeEK1CbpgZw4,428
|
|
2
|
+
x_model/field.py,sha256=w5BAoNA33a-uROaExx5Pr3jYQnUMKIYFYcPTjdBlx3M,2784
|
|
3
|
+
x_model/func.py,sha256=E7jDoHJGaFpKvxbHnT_lyBxUZeMo-GRd5gv9dLw7B9s,289
|
|
4
|
+
x_model/models.py,sha256=xalrke04TUv-pmzXwOir-naUREcBjaOXiOWQkUuj4Ic,2633
|
|
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,,
|
xn_model-1.0.6.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
x_model/__init__.py,sha256=JRsYD3P-8pHpEkCUgy6GuodkT7ZaY1AEeEK1CbpgZw4,428
|
|
2
|
-
x_model/field.py,sha256=w5BAoNA33a-uROaExx5Pr3jYQnUMKIYFYcPTjdBlx3M,2784
|
|
3
|
-
x_model/func.py,sha256=E7jDoHJGaFpKvxbHnT_lyBxUZeMo-GRd5gv9dLw7B9s,289
|
|
4
|
-
x_model/models.py,sha256=H_4bNlzzRJuo6qlfB9HLmWR421pIQHWWnBb2CDP-SfY,2830
|
|
5
|
-
xn_model-1.0.6.dist-info/METADATA,sha256=yc5mcKpcMB3eZoYalZ670MEdYTm6x4_D5EcHiU7jICY,961
|
|
6
|
-
xn_model-1.0.6.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
|
7
|
-
xn_model-1.0.6.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
|
|
8
|
-
xn_model-1.0.6.dist-info/RECORD,,
|
|
File without changes
|