xn-model 1.0.23__tar.gz → 1.0.25__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.4
2
2
  Name: xn-model
3
- Version: 1.0.23
3
+ Version: 1.0.25
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -23,7 +23,7 @@ class Model(TortModel):
23
23
  _sorts: tuple[str] = ("-id",)
24
24
 
25
25
  def __repr__(self, sep: str = " ") -> str:
26
- return sep.join(getattr(self, name_fragment) for name_fragment in self._name)
26
+ return sep.join(str(getattr(self, name_fragment)) for name_fragment in self._name)
27
27
 
28
28
  # @classmethod
29
29
  # def out_type(cls) -> type[BaseModel]:
@@ -35,8 +35,9 @@ class Model(TortModel):
35
35
  def in_type(cls, with_pk: bool = False) -> type[BaseUpd]:
36
36
  if not getattr(cls, cn := "Upd" if with_pk else "New", None):
37
37
  fields: list[tuple[str, type] | tuple[str, type, field]] = []
38
- for fn in cls._meta.db_fields:
39
- if (f := cls._meta.fields_map[fn]).pk and not with_pk:
38
+ meta = cls._meta
39
+ for fn in meta.db_fields:
40
+ if (f := meta.fields_map[fn]).pk and not with_pk:
40
41
  continue
41
42
  if getattr(f, "auto_now", None) or getattr(f, "auto_now_add", None):
42
43
  continue
@@ -44,18 +45,23 @@ class Model(TortModel):
44
45
  if f.default or f.null or (f.allows_generated and not f.pk) or not f.required:
45
46
  fld += (field(default_factory=dict) if f.default == {} else field(default=f.default),)
46
47
  fields.append(fld)
47
- # for fn in cls._meta.fk_fields:
48
- # f = cls._meta.fields_map[fn]
48
+ # for fn in meta.fk_fields:
49
+ # f = meta.fields_map[fn]
49
50
  # fld = fn+"_id", int
50
51
  # if f.default or f.allows_generated or f.null or not f.required:
51
52
  # fld += (field(default=f.default),)
52
53
  # fields.append(fld)
53
54
  pre_saves = [f.__name__ for f in cls._listeners[Signals.pre_save].get(cls, [])]
54
55
  dcl = make_dataclass(cls.__name__ + cn, fields, bases=(BaseUpd,), kw_only=True)
55
- dcl._unq = {o + "_id" for o in cls._meta.o2o_fields if o not in pre_saves}
56
- dcl._unq |= set((cls._meta.unique_together or ((),))[0])
57
- if with_pk:
58
- dcl._unq |= {"id"}
56
+ dcl._unq = {o + "_id" for o in meta.o2o_fields if o not in pre_saves}
57
+ dcl._unq |= set((meta.unique_together or ((),))[0])
58
+ dcl._unq |= {
59
+ k
60
+ for k, f in meta.fields_map.items()
61
+ if f.unique and k not in meta.backward_fk_fields | meta.backward_o2o_fields | meta.m2m_fields
62
+ }
63
+ if not with_pk:
64
+ dcl._unq -= {"id"}
59
65
  setattr(cls, cn, dcl)
60
66
 
61
67
  return getattr(cls, cn)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-model
3
- Version: 1.0.23
3
+ Version: 1.0.25
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
File without changes