Add history tracking functionality using django-pghistory; implement views, templates, and middleware for event serialization and context management

This commit is contained in:
pacnpal
2025-02-09 09:52:19 -05:00
parent a148d34cf9
commit 7ecf43f1a4
14 changed files with 210 additions and 7 deletions

14
core/middleware.py Normal file
View File

@@ -0,0 +1,14 @@
import pghistory
def setup_pghistory_context():
"""
Set up pghistory context middleware to track request information.
This function configures what contextual information is stored
with each history record.
"""
pghistory.context(lambda request: {
'user': str(request.user) if request.user.is_authenticated else None,
'ip': request.META.get('REMOTE_ADDR'),
'user_agent': request.META.get('HTTP_USER_AGENT'),
'session_key': request.session.session_key
})