Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Changes to only track field that changed #552

Open
aabanaag opened this issue Aug 9, 2023 · 1 comment
Open

[question] Changes to only track field that changed #552

aabanaag opened this issue Aug 9, 2023 · 1 comment

Comments

@aabanaag
Copy link

aabanaag commented Aug 9, 2023

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 aabanaag changed the title Changes to only track field that changed [question] Changes to only track field that changed Aug 9, 2023
@aqeelat
Copy link
Member

aqeelat commented Oct 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants