xn-model 0.10.4__tar.gz → 0.11.1__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-0.10.4/xn_model.egg-info → xn_model-0.11.1}/PKG-INFO +1 -1
- {xn_model-0.10.4 → xn_model-0.11.1}/x_model/model.py +5 -7
- {xn_model-0.10.4 → xn_model-0.11.1/xn_model.egg-info}/PKG-INFO +1 -1
- {xn_model-0.10.4 → xn_model-0.11.1}/.env.sample +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/.gitignore +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/.pre-commit-config.yaml +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/README.md +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/makefile +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/pyproject.toml +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/setup.cfg +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/tests/__init__.py +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/tests/test_db.py +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/x_model/__init__.py +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/x_model/field.py +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/x_model/func.py +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/x_model/pydantic.py +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/xn_model.egg-info/SOURCES.txt +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/xn_model.egg-info/dependency_links.txt +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/xn_model.egg-info/requires.txt +0 -0
- {xn_model-0.10.4 → xn_model-0.11.1}/xn_model.egg-info/top_level.txt +0 -0
|
@@ -15,13 +15,11 @@ class BaseModel(TortoiseModel):
|
|
|
15
15
|
# todo: refact: clean old garbage
|
|
16
16
|
id: int = fields.IntField(True)
|
|
17
17
|
|
|
18
|
-
_name: tuple[str] =
|
|
19
|
-
_sorts: tuple[str] =
|
|
18
|
+
_name: tuple[str] = ("name",)
|
|
19
|
+
_sorts: tuple[str] = ("-id",)
|
|
20
20
|
|
|
21
21
|
def repr(self, sep: str = " ") -> str:
|
|
22
|
-
|
|
23
|
-
return sep.join(getattr(self, name_fragment) for name_fragment in self._name)
|
|
24
|
-
return self.__repr__()
|
|
22
|
+
return sep.join(getattr(self, name_fragment) for name_fragment in self._name)
|
|
25
23
|
|
|
26
24
|
@classmethod
|
|
27
25
|
async def get_or_create_by_name(cls, name: str, attr_name: str = None, def_dict: dict = None) -> TortoiseModel:
|
|
@@ -42,7 +40,7 @@ class BaseModel(TortoiseModel):
|
|
|
42
40
|
async def upsert(cls, data: dict, oid=None):
|
|
43
41
|
meta: MetaInfo = cls._meta
|
|
44
42
|
|
|
45
|
-
# pop fields for relations from general data dict
|
|
43
|
+
# pop fields for relations from general data dict # todo: add backwards fields for save
|
|
46
44
|
m2ms = {k: data.pop(k) for k in meta.m2m_fields if k in data}
|
|
47
45
|
# bfks = {k: data.pop(k) for k in meta.backward_fk_fields if k in data}
|
|
48
46
|
# bo2os = {k: data.pop(k) for k in meta.backward_o2o_fields if k in data}
|
|
@@ -54,7 +52,7 @@ class BaseModel(TortoiseModel):
|
|
|
54
52
|
# unq = {key: data.pop(key) for key, ft in meta.fields_map.items() if ft.unique and key in data.keys()}
|
|
55
53
|
# # unq = meta.unique_together
|
|
56
54
|
# obj, is_created = await cls.update_or_create(data, **unq)
|
|
57
|
-
obj = (await cls.update_or_create(data,
|
|
55
|
+
obj = (await cls.update_or_create(data, id=oid))[0] if oid else await cls.create(**data)
|
|
58
56
|
|
|
59
57
|
# save relations
|
|
60
58
|
for k, ids in m2ms.items():
|
|
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
|
|
File without changes
|