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

Enable/disable logging actions (Create, Update, Delete) on specific Models #424

Open
rptmat57 opened this issue Sep 12, 2022 · 2 comments · May be fixed by #682
Open

Enable/disable logging actions (Create, Update, Delete) on specific Models #424

rptmat57 opened this issue Sep 12, 2022 · 2 comments · May be fixed by #682

Comments

@rptmat57
Copy link
Contributor

Hi,
First of all, thank you for this excellent app. I love how simple yet powerful this is.
My favorite part is being able to configure everything in settings.py so each users of a django project can decide if/what they want to track.

I was wondering if there is already a way (couldn't find it in the docs) to skip logs for Creation or Deletion of objects, or to only log Update actions.
One example would be having a lot of "read-only" type objects in a project where we don't want to clog the audit log table with all the creation of objects, but simply see when one is changed.
(even though I mentioned read-only, some objects can still be edited in the django admin interface).

If it doesn't exist yet, maybe this could be implemented as a list of Action IDs that could be set on a model.

Thanks again for the great work!

@hramezani
Copy link
Member

Hi,

I think it can be implemented by adding a new param to auditlog.register for example, actions. By default, it will track all actions.

The same param has to be added to AUDITLOG_INCLUDE_TRACKING_MODELS setting.

@mantulen
Copy link

mantulen commented Oct 24, 2023

Here is how I worked around this..

Created a function for reusability:

from auditlog.registry import auditlog

def disconnect_signal(model, receiver_name):
    for signal, receiver in auditlog._signals.items():
        if receiver.__name__ == receiver_name:
            signal.disconnect(sender=model, dispatch_uid=auditlog._dispatch_uid(signal, receiver))

And then after registering a model, we disconnect a given signal:

auditlog.register(MyModel)
disconnect_signal(MyModel, 'log_create')

Signal options are:

log_create
log_update
log_delete
log_access

Auditlog has a very similar internal function as this, but it disconnects all signals for a model, it is located in registry.py

@CleitonDeLima CleitonDeLima linked a pull request Oct 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants