field#
DTO domain types.
- class litestar.dto.field.Mark#
-
For marking field definitions on domain models.
- READ_ONLY = 'read-only'#
To mark a field that can be read, but not updated by clients.
- WRITE_ONLY = 'write-only'#
To mark a field that can be written to, but not read by clients.
- PRIVATE = 'private'#
To mark a field that can neither be read or updated by clients.
- __new__(value)#
- litestar.dto.field.dto_field(mark: Literal['read-only', 'write-only', 'private'] | Mark) dict[str, DTOField] #
Create a field metadata mapping.
- Parameters:
mark¶ – A DTO mark for the field, e.g., “read-only”.
- Returns:
A dict for setting as field metadata, such as the dataclass “metadata” field key, or the SQLAlchemy “info” field.
Marking a field automates its inclusion/exclusion from DTO field definitions, depending on the DTO’s purpose.
- litestar.dto.field.extract_dto_field(field_definition: FieldDefinition, field_info_mapping: Mapping[str, Any]) DTOField #
Extract
DTOField
instance for a model field.Supports
DTOField
to bet set viaAnnotated
or via a field info/metadata mapping.E.g.,
Annotated[str, DTOField(mark="read-only")]
orinfo=dto_field(mark="read-only")
.If a value is found in
field_info_mapping
, it is prioritized over the field definition’s metadata.