data_structures

class litestar.dto.data_structures.DTOData[原始碼]

基底類別:Generic[T]

DTO validated data and utility methods.

__init__(backend: DTOBackend, data_as_builtins: Any) None[原始碼]
create_instance(**kwargs: Any) T[原始碼]

Create an instance of the DTO validated data.

參數:

**kwargs -- Additional data to create the instance with. Takes precedence over DTO validated data.

update_instance(instance: T, **kwargs: Any) T[原始碼]

Update an instance with the DTO validated data.

參數:
  • instance -- The instance to update.

  • **kwargs -- Additional data to update the instance with. Takes precedence over DTO validated data.

as_builtins() Any[原始碼]

Return the DTO validated data as builtins.

class litestar.dto.data_structures.DTOFieldDefinition[原始碼]

基底類別:FieldDefinition

A model field representation for purposes of generating a DTO backend model type.

model_name: str

The name of the model for which the field is generated.

default_factory: Callable[[], Any] | None

Default factory of the field.

dto_field: DTOField

DTO field configuration.

__init__(raw: Any, annotation: Any, type_wrappers: tuple[type, ...], origin: Any, args: tuple[Any, ...], metadata: tuple[Any, ...], instantiable_origin: Any, safe_generic_origin: Any, inner_types: tuple[FieldDefinition, ...], default: Any, extra: dict[str, Any], kwarg_definition: KwargDefinition | DependencyKwarg | None, name: str, model_name: str, default_factory: Callable[[], Any] | None, dto_field: DTOField, passthrough_constraints: bool) None
passthrough_constraints: bool

Pass constraints of the source annotation to be validated by the DTO backend

classmethod from_field_definition(field_definition: FieldDefinition, model_name: str, default_factory: Callable[[], Any] | None, dto_field: DTOField, passthrough_constraints: bool = True) DTOFieldDefinition[原始碼]

Create a FieldDefinition from a FieldDefinition.

參數:
  • field_definition -- A FieldDefinition to create a FieldDefinition from.

  • model_name -- The name of the model.

  • default_factory -- Default factory function, if any.

  • dto_field -- DTOField instance.

  • passthrough_constraints -- Pass constraints of the source annotation to be validated by the DTO backend

回傳:

A FieldDefinition instance.