LogEntry
This class represents a record of an action performed in the administrative interface, tracking changes to specific objects by users. It stores metadata such as the action time, the user involved, the type of action performed, and a descriptive message of the changes. The class provides utility methods to identify the type of action and retrieve the specific object or administrative URL associated with the entry.
Attributes
| Attribute | Type | Description |
|---|---|---|
| action_time | [DateTimeField](../../../forms/fields/datetimefield.md?sid=django_forms_fields_datetimefield) = timezone.now | The date and time when the action was performed, defaulting to the current time. |
| user | [ForeignKey](../../../db/models/fields/related/foreignkey.md?sid=django_db_models_fields_related_foreignkey) | The user who performed the action recorded in the log entry. |
| content_type | [ForeignKey](../../../db/models/fields/related/foreignkey.md?sid=django_db_models_fields_related_foreignkey) | The type of the object that was acted upon, used to identify the model class. |
| object_id | [TextField](../../../db/models/fields/textfield.md?sid=django_db_models_fields_textfield) | The primary key of the object that was acted upon, stored as text. |
| object_repr | [CharField](../../../forms/fields/charfield.md?sid=django_forms_fields_charfield) | A string representation of the object after the action was performed, limited to 200 characters. |
| action_flag | [PositiveSmallIntegerField](../../../db/models/fields/positivesmallintegerfield.md?sid=django_db_models_fields_positivesmallintegerfield) | An integer representing the type of action performed, such as addition, change, or deletion. |
| change_message | [TextField](../../../db/models/fields/textfield.md?sid=django_db_models_fields_textfield) | A description of the changes made, which can be either a plain string or a JSON structure. |
| objects | [LogEntryManager](logentrymanager.md?sid=django_contrib_admin_models_logentrymanager) | The manager instance used to provide database query operations for LogEntry records. |
Methods
is_addition()
@classmethod
def is_addition() - > boolean
Checks if the log entry represents the creation of a new object.
Returns
| Type | Description |
|---|---|
boolean | True if the action_flag indicates an addition, False otherwise |
is_change()
@classmethod
def is_change() - > boolean
Checks if the log entry represents an update to an existing object.
Returns
| Type | Description |
|---|---|
boolean | True if the action_flag indicates a change, False otherwise |
is_deletion()
@classmethod
def is_deletion() - > boolean
Checks if the log entry represents the removal of an object.
Returns
| Type | Description |
|---|---|
boolean | True if the action_flag indicates a deletion, False otherwise |
get_change_message()
@classmethod
def get_change_message() - > string
If self.change_message is a JSON structure, interpret it as a change string, properly translated.
Returns
| Type | Description |
|---|---|
string | A formatted and translated string describing the specific fields or related objects that were modified |
get_edited_object()
@classmethod
def get_edited_object() - > object
Return the edited object represented by this log entry.
Returns
| Type | Description |
|---|---|
object | The model instance associated with this log entry's content type and object ID |
get_admin_url()
@classmethod
def get_admin_url() - > string
Return the admin URL to edit the object represented by this log entry.
Returns
| Type | Description |
|---|---|
string | The absolute URL path to the Django admin change form for the object, or None if the URL cannot be resolved |