Enable/disable logging actions (Create, Update, Delete) on specific Models
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!
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.
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