django-auditlog icon indicating copy to clipboard operation
django-auditlog copied to clipboard

[question] Changes to only track field that changed

Open aabanaag opened this issue 1 year ago • 1 comments

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'])

aabanaag avatar Aug 09 '23 07:08 aabanaag

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.

aqeelat avatar Oct 03 '23 14:10 aqeelat