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 22:59 +0200

1"""Related Feature List field 

2 

3Represents a parent->child 1:M relationship to another model:: 

4 

5 +--------------+ +-------------+ 

6 | parent table | | child table | 

7 +--------------+ +-------------+ 

8 | key |-----<<| parent_key | 

9 +--------------+ +-------------+ 

10 

11The value of the field is a list of child features. 

12 

13This object is implemented as a "related_multi_feature_list" with a single target model. 

14""" 

15 

16import gws 

17import gws.base.database.model 

18import gws.base.model.related_field as related_field 

19 

20from gws.plugin.model_field import related_multi_feature_list 

21 

22gws.ext.new.modelField('relatedFeatureList') 

23 

24 

25class Config(related_field.Config): 

26 """Configuration for related feature list field.""" 

27 

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.""" 

34 

35 

36class Props(related_field.Props): 

37 pass 

38 

39 

40class Object(related_multi_feature_list.Object): 

41 def configure_relationship(self): 

42 to_mod = self.get_model(self.cfg('toModel')) 

43 

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]