xn-model 1.0.4__tar.gz → 1.0.5__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.4
3
+ Version: 1.0.5
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -1,7 +1,6 @@
1
1
  from datetime import datetime
2
-
3
- from pydantic import ConfigDict
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 Model(BaseModel):
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
 
@@ -38,12 +45,8 @@ class Model(BaseModel):
38
45
  )
39
46
  return cls._pydIn
40
47
 
41
- # # # CRUD Methods # # #
42
- @classmethod
43
- async def get_one(cls, id_: int, **filters) -> PydanticModel:
44
- if obj := await cls.get_or_none(id=id_, **filters):
45
- return await cls.pyd().from_tortoise_orm(obj)
46
- raise LookupError(f"{cls.__name__}#{id_} not found")
48
+ async def one(self) -> PydanticModel:
49
+ return await self.pyd().from_tortoise_orm(self)
47
50
 
48
51
  @classmethod
49
52
  async def get_or_create_by_name(cls, name: str, attr_name: str = None, def_dict: dict = None) -> "Model":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xn-model
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
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