Schema Classes

Schema

class autoinvent_schema.schema.Schema(*, models)

Top-level schema object containing the models and other application-level information.

Parameters

models (t.Union[dict[str, Model], list[Model]]) –

Return type

None

models: dict[str, Model]

Map of model names to Model instances.

Models

class autoinvent_schema.schema.Model(*, name, label=None, label_plural=None, fields, field_order=None, display_field='name', is_singleton=False, has_index=True, index_field_order=None, table_link_field=None, table_can_sort=True, table_can_filter=True, table_can_page=True, has_create=True, create_field_order=None, has_delete=True, show_in_rel_delete=True, has_detail=True, show_in_search=None, detail_tabs=None, detail_field_order=None, tooltip_field_order=None, query_list=None, query_single=None, query_required_fields=None)

Describes a single model in the schema. A model has various views such as index, detail, create, and check delete, which the schema describes. The fields of a model can be attributes as well as relationships to other models.

Parameters
  • name (str) –

  • label (t.Optional[str]) –

  • label_plural (t.Optional[str]) –

  • fields (t.Union[dict[str, Field], list[Field]]) –

  • field_order (t.Optional[list[str]]) –

  • display_field (str) –

  • is_singleton (bool) –

  • has_index (bool) –

  • index_field_order (t.Optional[list[str]]) –

  • table_link_field (t.Optional[str]) –

  • table_can_sort (bool) –

  • table_can_filter (bool) –

  • table_can_page (bool) –

  • has_create (bool) –

  • create_field_order (t.Optional[list[str]]) –

  • has_delete (bool) –

  • show_in_rel_delete (bool) –

  • has_detail (bool) –

  • show_in_search (t.Optional[bool]) –

  • detail_tabs (t.Optional[list[DetailTab]]) –

  • detail_field_order (t.Optional[list[str]]) –

  • tooltip_field_order (t.Optional[list[str]]) –

  • query_list (t.Optional[str]) –

  • query_single (t.Optional[str]) –

  • query_required_fields (t.Optional[list[str]]) –

Return type

None

name: str

The internal name of the model. Used as the key in Schema.models and URLs.

label: str

The user-facing name of the model. Defaults to the name split on _ and in title case.

label_plural: str

The user-facing plural name of the model. Defaults to an attempt to pluralize label.

fields: dict[str, Field]

Map of field names to Field instances.

field_order: list[str]

Field names in the order they should be displayed if not overridden by a more specific attribute. Defaults to the insertion order of fields.

display_field: str

The field to access on an instance of the model that has a value to display for the instance. Used by get_display_value().

is_singleton: bool

A singleton model cannot be created or deleted. In a UI, it would have a single URL instead of index and detail pages.

has_index: bool

Whether an index page should be shown.

index_field_order: t.Optional[list[str]]

The fields to display as columns on the index page, in order. Used by get_index_field_order().

The field to use as a link to the detail page in a table. Defaults to the same field as display_field.

table_can_sort: bool

Whether the table can be sorted.

table_can_filter: bool

Whether the table can be filtered.

table_can_page: bool

Whether the table should be shown in multiple pages if there are too many rows.

has_create: bool

Whether instances can be created.

create_field_order: t.Optional[list[str]]

The fields to display as inputs on the create page, in order. Used by get_create_field_order().

has_delete: bool

Whether instances can be deleted.

show_in_rel_delete: bool

Whether this model should be shown when checking if it is safe to delete a related model.

has_detail: bool

Whether a detail page should be shown.

Whether instances of this model should show up in search.

detail_tabs: t.Optional[list[DetailTab]]

The detail page can be organized into tabs that each show a subset of the fields.

detail_field_order: t.Optional[list[str]]

The fields to display on the detail page, in order. Used by get_detail_field_order().

tooltip_field_order: t.Optional[list[str]]

The fields to display in link tooltips, in order. Used by get_tooltip_field_order().

query_list: str

The name of the query to get a list of instances of this model.

query_single: str

The name of the query to get a single instance of this model.

query_required_fields: list[str]

Fields to always include in any queries.

get_display_value(obj)

The value to display for a given instance of the model. By default this is the value of the attribute named by display_field.

Parameters

obj (Any) – An instance of the model.

Return type

str

get_index_field_order()

The fields to display as columns on the index page, in order. By default this uses index_field_order if that is set, or each field in field_order with Field.show_index enabled.

Return type

list[str]

get_create_field_order()

The fields to display as inputs on the create page, in order. By default this uses create_field_order if that is set, or each field in field_order with Field.show_create enabled.

Return type

list[str]

get_detail_field_order()

The fields to display on the detail page, in order. By default this uses:

Return type

list[str]

get_tooltip_field_order()

The fields to display in link tooltips, in order. By default this uses tooltip_field_order if that is set, or each field in field_order with Field.show_tooltip enabled.

Return type

list[str]

get_query_list_fields()

The fields to request in the list query. By default this uses index_field_order if that is set, or each field in field_order with Field.show_index or query_list_include enabled that is not marked Field.virtual. Fields in query_required_fields are always included.

Return type

list[str]

get_query_single_fields()

The fields to request in the single query. By default this uses detail_field_order if that is set, or each field in field_order with Field.show_detail or query_single_include enabled that is not marked Field.virtual. Fields in query_required_fields are always included.

Return type

list[str]

class autoinvent_schema.schema.DetailTab(*, name, label=None, fields, tabs=None)

A tab on the detail page. Can show a subset of the model’s fields as well as nested tabs.

Not required to show fields or tabs. If fields and tabs are left empty it specifies a named tab that will have custom behavior in the UI.

Parameters
Return type

None

name: str

The internal name of the tab. Used in URLs.

label: str

The user-facing name of the tab. Defaults to the name split on _ and in title case.

fields: list[str]

The fields to display on the tab, in order.

tabs: t.Optional[list[DetailTab]]

Sub-tabs to show under this tab. Typically shown under any fields in the tab.

Fields

class autoinvent_schema.schema.Field(*, name, type=<FieldType.string>, is_attribute=None, choices=None, label=None, label_help=None, no_data_value='N/A', input_help=None, is_disabled=False, can_sort=True, can_filter=True, can_edit=True, can_collapse=True, show_index=True, show_create=True, show_detail=True, show_tooltip=False, query_list_include=True, query_single_include=True, virtual=False)

Describes a single field in a model. A field is present as data or an input in a UI. Its attributes describe how it behaves when viewing, editing, and querying it.

Parameters
Return type

None

name: str

The internal name of the field. Used as the key in Model.fields.

type: t.Union[str, RelationshipInfo]

The type of data this field represents. Can affect how the data is displayed, validated, etc. A value from FieldType describes a basic type, or a string can be given for a custom type. A RelationshipInfo describes extra information about a relationship to another model. Defaults to "string".

is_attribute: bool

Whether this field should be treated as a key/value attribute or as a relationship table. Basic types default to True, relationship types default to False if they are in the “to one” direction.

choices: t.Optional[list[tuple[str, str]]]

A list of (value, label) tuples. If given, only these values are allowed for the field. As a shortcut, a list of strings can be passed if the value and label should be the same, or a dict mapping values to labels.

label: str

The user-facing name of the field. Defaults to the name split on _ and in title case.

label_help: t.Optional[str]

Info to display to the user describing the field. The UI might show this from an information icon next to the label.

no_data_value: t.Optional[str]

What to display if the field’s value is None. Use None to display empty space. Defaults to “N/A”.

input_help: t.Optional[str]

Info to display to the user describing the value being input. The UI might show this under an input when creating or editing.

is_disabled: bool

The input is visible but disabled.

can_sort: bool

When displayed in a table, this column can be sorted.

can_filter: bool

When displayed in a table, this field can be filtered on.

can_edit: bool

This field can be edited.

can_collapse: bool

When shown as a table (is_attribute is False), allow collapsing / hiding / minimizing the table.

show_index: bool

Show this field on the index page (and other tables). Only used if Model.index_field_order is not set.

show_create: bool

Show this field on the create page. Only used if Model.create_field_order is not set.

show_detail: bool

Show this field on the detail page (and other tables). Only used if Model.detail_field_order is not set.

show_tooltip: bool

Show this field in tooltips. Only used if Model.tooltip_field_order is not set.

query_list_include: bool

Request this field when querying for a list of items.

query_single_include: bool

Request this field when querying for a single item.

virtual: bool

A field that is not present in data or queries. It is a placeholder for custom local behavior.

class autoinvent_schema.schema.FieldType(value)

Built-in input types understood by Autoinvent.

class autoinvent_schema.schema.RelationshipInfo(*, type, target, backref=None, table_field_order=None)
Parameters
Return type

None

type: RelationshipType

A value from RelationshipType describing the size and direction of the relationship.

target: str

The name of the model this relationship is pointing to.

backref: t.Optional[str]

The name of the field on the target model that points to this model. Used to keep data in sync.

table_field_order: t.Optional[list[str]]

The fields of the target model to display as columns on the source model’s detail page table, in order. Used by get_table_field_order().

get_table_field_order()

The fields of the target model to display as columns on the source model’s detail page table, in order. By default this uses table_field_order if that is set, or calls Model.get_index_field_order() for the target.

Return type

list[str]

class autoinvent_schema.schema.RelationshipType(value)

Indicates the amount and direction of the relationship between two models.