-
Notifications
You must be signed in to change notification settings - Fork 439
Open
Description
Hi all,
I recently installed django-auditlog in Django Ninja,, and when I create new item, it works regardless if it's user or system (other lib affecting the db). However, for updates, there are only update logs created by celery beat and silk.
My current settings.py
INSTALLED_APPS = [
"admin_numeric_filter",
"modeltranslation",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_celery_beat",
"ninja",
.... (all registered apps)
"auditlog",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
....
"utils.middleware.AuditlogMiddleware"
]
### Django-auditlog settings ###
AUDITLOG_TWO_STEP_MIGRATION = True
AUDITLOG_USE_TEXT_CHANGES_IF_JSON_IS_NOT_PRESENT = True
AUDITLOG_STORE_JSON_CHANGES = True
AUDITLOG_CID_GETTER = None
AUDITLOG_CID_HEADER = None
AUDITLOG_USE_BASE_MANAGER = True
AUDITLOG_DISABLE_REMOTE_ADDR=False
AUDITLOG_INCLUDE_ALL_MODELS = True
AUDIT_EXCLUDE_TRACKING_FIELDS = ("created_at", "updated_at", "deleted_at")I have grabbed a custom Middleware (from #115 (comment)) based on hypothesis that the actor was not set properly and that why the logs were not creating.
class AuditlogMiddleware(middleware.AuditlogMiddleware):
def __call__(self, request):
remote_addr = self._get_remote_addr(request)
user = SimpleLazyObject(lambda: getattr(request, "user", None))
context = set_actor(actor=user, remote_addr=remote_addr)
with context:
return self.get_response(request)When I was debugging, I saw that user has been found in __call__ when I update a model via Django admin panel.
What am I missing here? Or did I misconfig something here?
Thank you in advance!
2ykwang
Metadata
Metadata
Assignees
Labels
No labels