How to implement Django model audit trail? How can you log in using the save () method?

I want to track the user who creates and then updates all the model data. I have "user" information in the registered UserProfile user (all users must be logged in to update these entries).

+8
django
source share
4 answers

It looks like you are looking for django-reversion , which allows you to track all the changes in this model, including some metadata about the change (for example, who did it).

+3
source share

Django models do not (specifically) have access to the request object. You must pass it to the model in the form.

+1
source share

The fastest way to automatically determine the user field for all changes made to the administrator will be to override the save_model method in your administrator class (from Django docs):

 class ArticleAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.user = request.user obj.save() 

Otherwise, you can use something like django-revision mentioned by Dominic Rodger.

+1
source share

I find django-simple-history very easy to use. It is important to note that it has a setting that allows you to track the cause of the changes, which can be strategically used to obtain information from users to find out the reason.

0
source share

All Articles