xn-model 1.0.6__tar.gz → 1.0.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xn-model
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,7 @@
1
1
  from datetime import datetime
2
+
2
3
  from pydantic import ConfigDict, BaseModel
3
- from tortoise import Model as TrtModel
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 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):
16
+ class Model(TortModel):
24
17
  id: int = IntField(True)
25
18
 
26
- _pyd: type[PydanticModel] = None # overridable
27
- _pydIn: type[PydIn | PydanticModel] = None # overridable
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 repr(self) -> str:
32
- return " ".join(getattr(self, name_fragment) for name_fragment in self._name)
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._pyd:
37
- cls._pyd = pydantic_model_creator(cls, name=cls.__name__)
38
- return cls._pyd
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._pydIn:
43
- cls._pydIn = pydantic_model_creator(
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._pydIn
39
+ return cls._in
47
40
 
48
41
  # # # CRUD Methods # # #
49
42
  @classmethod
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xn-model
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -10,6 +10,7 @@ x_model/__init__.py
10
10
  x_model/field.py
11
11
  x_model/func.py
12
12
  x_model/models.py
13
+ x_model/types.py
13
14
  xn_model.egg-info/PKG-INFO
14
15
  xn_model.egg-info/SOURCES.txt
15
16
  xn_model.egg-info/dependency_links.txt
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