Coverage for gws-app/gws/plugin/model_field/related_feature_list/__init__.py: 100%
19 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Related feature list field.
3Represents a parent->child 1:M relationship to another model::
5 +--------------+ +-------------+
6 | parent table | | child table |
7 +--------------+ +-------------+
8 | fromColumn |-----<<| toColumn |
9 +--------------+ +-------------+
11The value of the field is a list of child features. ``fromColumn`` is the key
12column in this model's table, by default its primary key; ``toColumn`` is the
13foreign key column in the child model.
15The field is implemented as a ``relatedMultiFeatureList`` with a single child
16model, so it reads and writes the relationship in the same way. Without a
17configured widget, the field uses a ``featureList`` widget.
19Example::
21 fields+ {
22 name "pois"
23 type "relatedFeatureList"
24 fromColumn "id"
25 toModel "model_poi"
26 toColumn "category_id"
27 widget.type "featureList"
28 }
29"""
31import gws
32import gws.base.database.model
33import gws.base.model.related_field as related_field
35from gws.plugin.model_field import related_multi_feature_list
38@gws.ext.config.modelField('relatedFeatureList')
39class Config(related_field.Config):
40 """Field listing related features in another model."""
42 fromColumn: str = ''
43 """Key column in this table, primary key by default."""
44 toModel: str
45 """UID of the related model."""
46 toColumn: str
47 """Foreign key column in the related model."""
50@gws.ext.props.modelField('relatedFeatureList')
51class Props(related_field.Props):
52 pass
55@gws.ext.object.modelField('relatedFeatureList')
56class Object(related_multi_feature_list.Object):
57 """Related feature list field object."""
59 def configure_relationship(self):
60 dst_mod = self.get_model(self.cfg('toModel'))
62 self.rel = related_field.Relationship(
63 src=related_field.RelRef(
64 model=self.model,
65 keyName=self.model.column(self.cfg('fromColumn') or self.model.uidName).name,
66 ),
67 dstList=[
68 related_field.RelRef(
69 model=dst_mod,
70 keyName=dst_mod.column(self.cfg('toColumn')).name,
71 )
72 ],
73 )
74 self.rel.dst = self.rel.dstList[0]