Saltar a contenido

dorm.contrib.audit

Trazabilidad por campo. Decora un modelo con @audited(fields=[...]) para registrar cada cambio a una tabla hermana <Name>Audit.

API

dorm.contrib.audit.audited(fields: list[str] | None = None, *, actor_getter: Callable[[], Any] | None = None, using: str = 'default') -> Callable[[type], type]

Class decorator that records a per-field audit trail.

Parameters:

Name Type Description Default
fields list[str] | None

column names to track. None (default) tracks every concrete, non-PK column.

None
actor_getter Callable[[], Any] | None

zero-arg callable returning the principal performing the write (user id / email / opaque token). Result is stringified; None is allowed.

None
using str

database alias for the audit-row insert. Defaults to "default" — matches the source row's alias in most single-DB setups.

'default'

dorm.contrib.audit.audit_history(instance: Any) -> Any

Return a queryset of audit rows for instance, newest first.

Equivalent to Model._audit_model.objects.filter(target_id=instance.pk) — sugar so callers don't need to know the sibling model's name.

Raises :class:LookupError when instance's class isn't decorated with :func:audited.