gws.base.model.related_field

Base class for related fields.

Source code: gws.base.model.related_field

Module Contents

class gws.base.model.related_field.Config

Bases: gws.base.model.field.Config

Bases: gws.Data

Link table of a many-to-many relationship.

dstKeyName: str

Column in the link table that refers to the related model.

srcKeyName: str

Column in the link table that refers to the source model.

tableName: str

The link table name.

class gws.base.model.related_field.Object

Bases: gws.base.model.field.Object

Base related field.

Links features of the field’s model to features of other database models. Provides the relationship description, conversion of related features to and from props, and database helpers to read and update the keys of related features. Subclasses describe the link in configure_relationship.

model: gws.DatabaseModel

The model of this field.

rel: Relationship

The relationship of this field.

configure_relationship()

Set up the relationship rel.

Called after configuration. The base implementation does nothing.

configure_widget()
find_relatable_features(search, mc)
from_props(feature, mc)
get_model(uid: str) → gws.DatabaseModel

Return a model by uid.

Parameters:

uid – The model uid.

Returns:

The model.

Raises:

gws.ConfigurationError – If the model is not found.

key_column(ref: RelRef) → gws.lib.sa.Column

Return the key column of a relationship side.

Parameters:

ref – The relationship side.

Returns:

The column ref.keyName of ref.model.

key_for_uid(model: gws.DatabaseModel, key_column: gws.lib.sa.Column, uid: gws.FeatureUid, mc: gws.ModelContext)

Return the key value of the feature with the given uid.

Parameters:
  • model – The model to query.

  • key_column – The key column.

  • uid – The feature uid.

  • mc – The model context.

Returns:

The key value, or None if the feature is not found.

Return a column of the link table.

Parameters:

name – The column name.

Returns:

The column.

Return the link table of the relationship.

post_configure()
related_field(dst: RelRef) → gws.ModelField | None

Find the field of a related model that describes the reverse relationship.

Parameters:

dst – The related side of the relationship.

Returns:

The field of dst.model whose relationship starts at dst.model and dst.keyName, or None if there is no such field.

related_models()
to_props(feature, mc)
class gws.base.model.related_field.Props

Bases: gws.base.model.field.Props

class gws.base.model.related_field.Relationship(*args, **kwargs)

Bases: gws.Data

Relationship between the model of a field and related models.

deleteCascade: bool = False

When unlinking related features, delete them instead of clearing their key.

dst: RelRef

The related side, for relationships with a single related model.

dstList: list[RelRef]

The related sides.

The link table, for many-to-many relationships.

src: RelRef

The side of the field’s own model.

class gws.base.model.related_field.RelRef(*args, **kwargs)

Bases: gws.Data

One side of a relationship.

keyName: str

The column that takes part in the relationship.

model: gws.DatabaseModel

The model.