Coverage for gws-app/gws/plugin/model_field/related_feature_list/__init__.py: 0%

19 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-17 01:37 +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 fromColumn: str = '' 

27 """key column in this table, primary key by default""" 

28 toModel: str 

29 """related model""" 

30 toColumn: str 

31 """foreign key column in the related model""" 

32 

33 

34class Props(related_field.Props): 

35 pass 

36 

37 

38class Object(related_multi_feature_list.Object): 

39 

40 def configure_relationship(self): 

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

42 

43 self.rel = related_field.Relationship( 

44 src=related_field.RelRef( 

45 model=self.model, 

46 table=self.model.table(), 

47 key=self.column_or_uid(self.model, self.cfg('fromColumn')), 

48 uid=self.model.uid_column(), 

49 ), 

50 tos=[ 

51 related_field.RelRef( 

52 model=to_mod, 

53 table=to_mod.table(), 

54 key=to_mod.column(self.cfg('toColumn')), 

55 uid=to_mod.uid_column(), 

56 ) 

57 ] 

58 ) 

59 self.rel.to = self.rel.tos[0]