gws.plugin.model_field.related_multi_feature_list

Related multi feature list field.

Represents a 1:M relationship between a “parent” and multiple “child” tables:

+---------+         +------------+
| parent  |         | child 1    |
+---------+         +------------+
| key     |-------<<| parent_key |
|         |         +------------+
|         |
|         |         +------------+
|         |         | child 2    |
|         |         +------------+
|         |-------<<| parent_key |
|         |         +------------+
|         |
|         |         +------------+
|         |         | child 3    |
|         |         +------------+
|         |-------<<| parent_key |
+---------+         +------------+

The value of the field is the list of child features from all child models. fromColumn is the key column in this model’s table, by default its primary key; each entry in related names a child model and its foreign key column.

When a feature is written, child features in the list get their foreign key set to the parent key. Child features no longer in the list are unlinked by clearing their foreign key. When a parent feature is deleted, its children are unlinked in the same way. Child models the user may not edit are skipped. When a child feature is created together with a parent feature, its foreign key is set to the parent key. Without a configured widget, the field uses a featureList widget.

Example:

fields+ {
    name "documents"
    type "relatedMultiFeatureList"
    related [
        { toModel "model_photo" toColumn "parent_id" }
        { toModel "model_report" toColumn "parent_id" }
    ]
}

Source code: gws.plugin.model_field.related_multi_feature_list

Package Contents

class gws.plugin.model_field.related_multi_feature_list.Config

Bases: gws.base.model.related_field.Config

Field listing related features from several models.

fromColumn: str = ''

Key column in this table, primary key by default.

related: list[RelatedItem]

Related models and keys.

class gws.plugin.model_field.related_multi_feature_list.Object

Bases: gws.base.model.related_field.Object

Related multi feature list field object.

attributeType
after_create(feature, mc)
after_delete(features, mc)
after_select(features, mc)
after_update(feature, mc)
after_write(feature: gws.Feature, key, mc: gws.ModelContext)

Link the child features in the field value to a written feature and unlink the others.

Does nothing if the user may not write the field or the maximum relation depth is reached. Child models the user may not edit are skipped.

Parameters:
  • feature – The created or updated feature.

  • key – Value of the key column of the feature.

  • mc – The model context.

before_delete(feature, mc)
configure_relationship()

Unlink child features from their parent.

Clears the foreign key of the child features, or deletes them if the relationship has deleteCascade set.

Parameters:
  • dst – The child side of the relationship.

  • dst_uids – Uids of the child features.

  • mc – The model context.

dst_uids_for_key(dst: gws.base.model.related_field.RelRef, key, mc)

Find the uids of the child features that refer to a parent key.

Parameters:
  • dst – The child side of the relationship.

  • key – The parent key value.

  • mc – The model context.

Returns:

A set of child feature uids as strings.

class gws.plugin.model_field.related_multi_feature_list.Props

Bases: gws.base.model.related_field.Props

class gws.plugin.model_field.related_multi_feature_list.RelatedItem(*args, **kwargs)

Bases: gws.Data

Related model and its key column.

toColumn: str

Foreign key column in the related model.

toModel: str

UID of the related model.