2323from django .utils .encoding import smart_str
2424from django .utils .translation import gettext_lazy as _
2525
26+ from auditlog import get_logentry_model
2627from auditlog .diff import mask_str
2728
2829DEFAULT_OBJECT_REPR = "<error forming object repr>"
@@ -107,7 +108,7 @@ def log_m2m_changes(
107108 except ObjectDoesNotExist :
108109 object_repr = DEFAULT_OBJECT_REPR
109110 kwargs .setdefault ("object_repr" , object_repr )
110- kwargs .setdefault ("action" , LogEntry .Action .UPDATE )
111+ kwargs .setdefault ("action" , get_logentry_model () .Action .UPDATE )
111112
112113 if isinstance (pk , int ):
113114 kwargs .setdefault ("object_id" , pk )
@@ -302,17 +303,7 @@ def _mask_serialized_fields(
302303 return data
303304
304305
305- class LogEntry (models .Model ):
306- """
307- Represents an entry in the audit log. The content type is saved along with the textual and numeric
308- (if available) primary key, as well as the textual representation of the object when it was saved.
309- It holds the action performed and the fields that were changed in the transaction.
310-
311- If AuditlogMiddleware is used, the actor will be set automatically. Keep in mind that
312- editing / re-saving LogEntry instances may set the actor to a wrong value - editing LogEntry
313- instances is not recommended (and it should not be necessary).
314- """
315-
306+ class AbstractLogEntry (models .Model ):
316307 class Action :
317308 """
318309 The actions that Auditlog distinguishes: creating, updating and deleting objects. Viewing objects
@@ -391,6 +382,7 @@ class Action:
391382 objects = LogEntryManager ()
392383
393384 class Meta :
385+ abstract = True
394386 get_latest_by = "timestamp"
395387 ordering = ["-timestamp" ]
396388 verbose_name = _ ("log entry" )
@@ -550,6 +542,21 @@ def _get_changes_display_for_fk_field(
550542 return f"Deleted '{ field .related_model .__name__ } ' ({ value } )"
551543
552544
545+ class LogEntry (AbstractLogEntry ):
546+ """
547+ Represents an entry in the audit log. The content type is saved along with the textual and numeric
548+ (if available) primary key, as well as the textual representation of the object when it was saved.
549+ It holds the action performed and the fields that were changed in the transaction.
550+
551+ If AuditlogMiddleware is used, the actor will be set automatically. Keep in mind that
552+ editing / re-saving LogEntry instances may set the actor to a wrong value - editing LogEntry
553+ instances is not recommended (and it should not be necessary).
554+ """
555+
556+ class Meta (AbstractLogEntry .Meta ):
557+ swappable = "AUDITLOG_LOGENTRY_MODEL"
558+
559+
553560class AuditlogHistoryField (GenericRelation ):
554561 """
555562 A subclass of py:class:`django.contrib.contenttypes.fields.GenericRelation` that sets some default
@@ -570,7 +577,7 @@ class AuditlogHistoryField(GenericRelation):
570577 """
571578
572579 def __init__ (self , pk_indexable = True , delete_related = False , ** kwargs ):
573- kwargs ["to" ] = LogEntry
580+ kwargs ["to" ] = get_logentry_model ()
574581
575582 if pk_indexable :
576583 kwargs ["object_id_field" ] = "object_id"
0 commit comments