Mutations¶
Sync helpers¶
apply_input ¶
apply_input(
instance: Model,
data: Any,
*,
field_map: dict[str, str] | None = None,
exclude_fields: list[str] | None = None,
) -> ChangeResult
Set attributes from data onto instance without saving.
Returns a :class:ChangeResult describing fields whose value actually
changed. Useful when a service wants to inspect what the input would
change before deciding whether to persist.
create_from_input ¶
create_from_input(
model: type[Model],
data: Any,
*,
field_map: dict[str, str] | None = None,
exclude_fields: list[str] | None = None,
m2m: dict[str, Any] | None = None,
) -> ChangeResult
Build, save(), and return a fresh instance of model.
Regular fields come from data (a dataclass, dict, or object with
__dict__); M2M assignments are applied post-save via the m2m
kwarg, mapping attribute name to the value to set().
update_from_input ¶
update_from_input(
instance: Model,
data: Any,
*,
field_map: dict[str, str] | None = None,
exclude_fields: list[str] | None = None,
m2m: dict[str, Any] | None = None,
update_fields: bool | list[str] = True,
) -> ChangeResult
Update instance with values from data, persisting only deltas.
By default (update_fields=True), the save call uses
update_fields=<changed> to write the minimal set of columns.
auto_now=True fields (e.g. updated_at) are automatically added to
that list so they are refreshed alongside the mutation. Pass False to
perform a full save, or an explicit list to control exactly which columns
are written (no auto-injection in that case).
Async helpers¶
acreate_from_input
async
¶
acreate_from_input(
model: type[Model],
data: Any,
*,
field_map: dict[str, str] | None = None,
exclude_fields: list[str] | None = None,
m2m: dict[str, Any] | None = None,
) -> ChangeResult
Async sibling of :func:create_from_input using asave()/aset().
aupdate_from_input
async
¶
aupdate_from_input(
instance: Model,
data: Any,
*,
field_map: dict[str, str] | None = None,
exclude_fields: list[str] | None = None,
m2m: dict[str, Any] | None = None,
update_fields: bool | list[str] = True,
) -> ChangeResult
Async sibling of :func:update_from_input using asave()/aset().