Coverage for gws-app/gws/plugin/model_field/related_feature_list/__init__.py: 100%
19 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
1"""Related Feature List field
3Represents a parent->child 1:M relationship to another model::
5 +--------------+ +-------------+
6 | parent table | | child table |
7 +--------------+ +-------------+
8 | key |-----<<| parent_key |
9 +--------------+ +-------------+
11The value of the field is a list of child features.
13This object is implemented as a "related_multi_feature_list" with a single target model.
14"""
16import gws
17import gws.base.database.model
18import gws.base.model.related_field as related_field
20from gws.plugin.model_field import related_multi_feature_list
22gws.ext.new.modelField('relatedFeatureList')
25class Config(related_field.Config):
26 """Configuration for related feature list field."""
28 fromColumn: str = ''
29 """Key column in this table, primary key by default."""
30 toModel: str
31 """Related model."""
32 toColumn: str
33 """Foreign key column in the related model."""
36class Props(related_field.Props):
37 pass
40class Object(related_multi_feature_list.Object):
41 def configure_relationship(self):
42 to_mod = self.get_model(self.cfg('toModel'))
44 self.rel = related_field.Relationship(
45 src=related_field.RelRef(
46 model=self.model,
47 table=self.model.table(),
48 key=self.column_or_uid(self.model, self.cfg('fromColumn')),
49 uid=self.model.uid_column(),
50 ),
51 tos=[
52 related_field.RelRef(
53 model=to_mod,
54 table=to_mod.table(),
55 key=to_mod.column(self.cfg('toColumn')),
56 uid=to_mod.uid_column(),
57 )
58 ],
59 )
60 self.rel.to = self.rel.tos[0]