Skip to content

Conversation

@arman-sharker
Copy link

Summary

This PR introduces a reusable AuditAdmin base class under the common/ folder to standardize the handling of created_by and updated_by fields in Django admin.

What it does

  • Adds AuditAdmin class extending ModelAdmin
  • Automatically sets created_by (on object creation) and updated_by (on any save)
  • Intended for models inheriting from BaseModel with audit fields

Why

Reduces repetition and enforces consistency across admin configurations that require audit tracking.

Usage

In any admin class:

from common.admin import AuditAdmin

class MyModelAdmin(AuditAdmin):
    ...

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants