Skip to main content

Field descriptor reference

Every option a Field accepts, and what each one produces in the schema.

A view generator takes plain field names when the defaults are fine. Wrap a name in a Field when the view needs to say more about it — a different label, an alignment, a condition, an action.

Declaration​

from habarico.schema import Field
from habarico.schema.generators import ListViewSchemaGenerator

ListViewSchemaGenerator(fields=[
"name",
Field(name="price", short_label="Price", text_align="right", postfix=" CZK"),
Field(name="stock", sortable=True, sort_by="stock_total"),
])

Field imports from habarico.schema; it is an alias of the underlying FieldDescriptor class, which lives in habarico.schema.fields.

Options​

OptionTypeDefaultDescription
name (required)str—Field name, as exposed by the serializer
labelstrlabel from the serializerColumn header and form label
short_labelstr—Label used where space is tight, e.g. a datagrid column
help_textstrhelp text from the modelHint under the input
sortableboolfrom the admin's ordering_fieldsWhether the list may be sorted by the column
sort_bystrnameField the backend sorts by when the column is clicked
read_onlyboolfrom the serializerRenders the value but never accepts it
write_onlyboolfrom the serializerAccepts the value but never returns it
default_valueAny—Initial value in a create form
actionAction | str | ActionSchema—Makes the value a button running that action
wrapperFieldWrapperProperties—Groups several fields into one cell — see below
show_querystr—Condition expression; the field disappears when it is falsy
required_querystr—Condition expression; the field becomes required when it is truthy
text_alignTextAlignType"left""left", "right" or "center"
prefixstr—Text rendered before the value
postfixstr—Text rendered after the value
relationRelationFieldOptions—Behaviour of a relation field — see below
validatorslist[ValidatorRule]rules extracted from the serializer fieldFrontend validation rules — see Validation rules in the schema

show_query and required_query land under options.dynamic_render in the schema, which is what the frontend's conditional rendering reads. Both are evaluated against the current form data or record. They are condition expressions with a fixed grammar — identifiers with dot paths, string / number / boolean / null / undefined literals, comparisons (==, !=, ===, !==, <, <=, >, >=), && / || / ! and parentheses — interpreted by the frontend, never executed as JavaScript. Anything outside that grammar is rejected as an invalid expression.

RelationFieldOptions​

Applies to fields with format: "relation" or "tree-relation".

OptionTypeDefaultDescription
filterslist[KeyValue]—Restricts the choices offered
sortSortDescriptor—Orders the choices
show_linkbool—Renders the value as a link to the related record
link_modeViewModeType—redirect, dialog or sidepanel
dialog_widthDialogWidthType | str—link_mode="dialog" only — a breakpoint ("xs"…"xl") or any CSS width
keep_linked_parentbool—Keeps the parent in the URL when following the link
show_edit_buttonbool—Adds an inline edit button next to the picker
show_create_buttonbool—Adds an inline create button next to the picker
preserve_orderboolTrue when sort is unset, else FalseKeeps the order of values as stored, instead of re-sorting
parentstr—Field forming the hierarchy of a tree-relation
caution

preserve_order defaults from sort, not from None: setting a sort silently turns order preservation off. Set both explicitly when you want a sorted picker over an order-preserving value.

FieldOptions​

The same options can be given as a FieldOptions object where an API takes one, plus the format-specific groups:

OptionTypeDescription
choicesChoicesFieldOptionsicons_key — key into the frontend's iconsMap, giving each enum chip an icon
imageImageFieldOptionsresize_width in pixels and crop_aspect_ratio (e.g. 1.5 for 3:2), applied before upload
aiAiFieldOptionssource_fields — the fields used as context when predicting this one
numberNumberFieldOptionsIntl.NumberFormat options: style ("currency" / "unit"), currency, unit, minimum_fraction_digits, maximum_fraction_digits
phonePhoneFieldOptionsdefault_region and allowed_regions of the country selector
uploadUploadFieldOptionsChunked-upload transport — injected by the uploads app, not written by hand
targetLinkTargetType | strWhere a file or url link opens
validatorslist[ValidatorRule]Frontend validation rules — see Validation rules in the schema
caution

target is stored without the leading underscore — "blank", not "_blank". The frontend prepends it when it renders the link.

FieldWrapper​

Renders several fields as one cell — a street and a house number in a single column.

from habarico.schema import FieldWrapper

FieldWrapper(name="address", label="Address", fields=["street", "city"], divider=", ")
OptionTypeDefaultDescription
name (required)str—Name of the resulting pseudo-field
fields (required)Fields—Fields to combine
dividerstr—Text placed between them
label / short_labelstr—As on a plain field
show_querystr—Condition for showing the whole group
text_alignTextAlignType—Alignment of the combined cell

FieldAction​

Turns a field into a trigger for an action, without repeating the name twice.

from habarico.schema import FieldAction

FieldAction(name="approve", label="Approve")

It is a Field whose action defaults to its own name, so the two lines below are the same thing:

FieldAction(name="approve")
Field(name="approve", action="approve")

It accepts name, label, short_label, action, show_query and text_align.

Generated schema​

A descriptor becomes one entry of the view's fields, and the frontend maps it to a component from the field's type and format — the descriptor only shapes how that component is configured.

Note where each option lands: label, short_label, sortable, sort_by, read_only, write_only, default_value, action and wrapper are properties of the descriptor itself, while text_align, prefix, postfix, relation, show_query and required_query are collected into options.

{"type": "field", "name": "price", "short_label": "Price",
"options": {"text_align": "right", "postfix": " CZK"}}

options is omitted entirely when none of the options that feed it is set.

See also​