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

Is there a way to change the 'User' when logging?

Open ghost opened this issue 4 years ago • 5 comments

Currently, due to my app being an API it logs that the 'system' made the change. In each of the API calls, I'm passing a Token for authentification which corresponds to a certain user. Is there a way to change out which table or resource django-auditlog looks for when someone makes a change? Screenshot_1

ghost avatar Jan 10 '21 10:01 ghost

Have you found a way? I have the same problem as you。

showniu avatar Mar 30 '21 01:03 showniu

@lijiapengsa no luck currently, I'll try to dive into the source code when I get the time to actually try to work something out

ghost avatar Apr 02 '21 09:04 ghost

@MislavPeric I use a different method for logging users, using a mixin class to append the username to the additional_data field. The result looks like the following: image

showniu avatar Apr 13 '21 06:04 showniu

Have you set the actors middleware?

dbaldy avatar Sep 06 '21 12:09 dbaldy

Found a good solution in this comment.

I changed the is_authenticated(request.user) line to request.user.is_authenticated (since auditlog.compat is no longer included in the package, and the function was only used for backwards compatibility). Also updated django.utils.functional.curry to functools.partial.

pedrogut avatar Sep 16 '21 07:09 pedrogut