Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions common/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.contrib import admin

class AuditAdmin(admin.ModelAdmin):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, this only works if you're doing this from the Django admin, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only for django admin.

"""
Base admin class to automatically set created_by and updated_by fields
for models inheriting from BaseModel. Inherit this for all admin models
using audit fields.
"""
def save_model(self, request, obj, form, change):
if not obj.pk and not obj.created_by:
obj.created_by = request.user
obj.updated_by = request.user
super().save_model(request, obj, form, change)