Apply views
- async AsyncCogniteClient.data_modeling.views.apply( ) View | ViewList
Create or update (upsert) one or more views.
- Parameters:
view (ViewApply | Sequence[ViewApply]) – View(s) to create or update.
- Returns:
Created view(s)
- Return type:
Examples
Create new views:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.data_modeling import ( ... ViewApply, ... MappedPropertyApply, ... ContainerId, ... ) >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> views = [ ... ViewApply( ... space="mySpace", ... external_id="myView", ... version="v1", ... properties={ ... "someAlias": MappedPropertyApply( ... container=ContainerId("mySpace", "myContainer"), ... container_property_identifier="someProperty", ... ), ... }, ... ) ... ] >>> res = client.data_modeling.views.apply(views)
Create views with edge relations:
>>> from cognite.client.data_classes.data_modeling import ( ... ContainerId, ... DirectRelationReference, ... MappedPropertyApply, ... MultiEdgeConnectionApply, ... ViewApply, ... ViewId, ... ) >>> work_order_for_asset = DirectRelationReference( ... space="mySpace", external_id="work_order_for_asset" ... ) >>> work_order_view = ViewApply( ... space="mySpace", ... external_id="WorkOrder", ... version="v1", ... name="WorkOrder", ... properties={ ... "title": MappedPropertyApply( ... container=ContainerId(space="mySpace", external_id="WorkOrder"), ... container_property_identifier="title", ... ), ... "asset": MultiEdgeConnectionApply( ... type=work_order_for_asset, ... direction="outwards", ... source=ViewId("mySpace", "Asset", "v1"), ... name="asset", ... ), ... }, ... ) >>> asset_view = ViewApply( ... space="mySpace", ... external_id="Asset", ... version="v1", ... name="Asset", ... properties={ ... "name": MappedPropertyApply( ... container=ContainerId("mySpace", "Asset"), ... name="name", ... container_property_identifier="name", ... ), ... "work_orders": MultiEdgeConnectionApply( ... type=work_order_for_asset, ... direction="inwards", ... source=ViewId("mySpace", "WorkOrder", "v1"), ... name="work_orders", ... ), ... }, ... ) >>> res = client.data_modeling.views.apply([work_order_view, asset_view])