django-auditlog
django-auditlog copied to clipboard
[question] Changes to only track field that changed
So I have a specific requirement where I have categories of changes, and I don't have use for the values that changed but only with the fields that changed. Is it possible to modify it by handling it via pre_log? (i.e changes: ['requirements, 'details'])
you can probably add this to your model
class MyModel(models.Model):
__audit_log_change_reason: str = ""
@property
def audit_log_change_reason(self) -> str:
return self.__audit_log_change_reason
@audit_log_change_reason.setter
def audit_log_change_reason(self, value: str) -> None:
self.__audit_log_change_reason = value
def get_additional_data(self):
data = {}
if self.audit_log_change_reason:
data["change_reason"] = self.audit_log_change_reason
return data
and then create a pre_save signal for your model to populate the field.