Source code for superdjango.db.audit.mixins

# Imports

from django.db import models

# Exports

__all__ = (
    "AuditMixin",
)

# Mixins


[docs]class AuditMixin(models.Model): """Base for other abstract auditing models. The class serves two purposes: 1. Provide a centralized ``audit()`` method that child classes may call to save audit data. 2. Act as a flag for the ``is_audit_model()`` function to indicate the presence of audit functionality. """ class Meta: abstract = True
[docs] def audit(self, user, commit=True): """Save the model along with audit data. :param user: The user saving the record. :type user: AUTH_USER_MODEL :param commit: Whether to save immediately. :type commit: bool """ if commit: self.save()