Skip to content

Centurion Audit Model


This model is the base model Audit model within Centurion ERP

Bases: CenturionModel

Centurion Audit History

This model is responsible for recording change to a model. The saving of model history is via the delete and save signals

Attributes

action

action = IntegerField(blank=False, choices=Actions, help_text='History action performed', null=True, validators=[validate_field_not_none], verbose_name='Action')

after

after = JSONField(blank=True, help_text='Value Change to', null=True, validators=[validate_field_not_none], verbose_name='After')

before

before = JSONField(blank=True, help_text='Value before Change', null=True, validators=[validate_field_not_none], verbose_name='Before')

content_type

content_type = ForeignKey(ContentType, blank=True, help_text='Model this history is for', null=False, on_delete=CASCADE, validators=[validate_field_not_none], verbose_name='Content Model')

model_notes

model_notes = None

page_layout

page_layout: list = []

table_fields

table_fields: list = ['created', 'action', 'content', 'user', 'nbsp', ['before', 'after']]

url_model_name

url_model_name

user

user = ForeignKey(AUTH_USER_MODEL, blank=False, help_text='User whom performed the action', null=False, on_delete=DO_NOTHING, validators=[validate_field_not_none], verbose_name='User')

Classes

Actions

Bases: IntegerChoices

Attributes

ADD
ADD = (1, 'Create')
DELETE
DELETE = (3, 'Delete')
UPDATE
UPDATE = (2, 'Update')

Meta

Attributes

db_table
db_table = 'core_audithistory'
ordering
ordering = ['-created']
verbose_name
verbose_name = 'Model History'
verbose_name_plural
verbose_name_plural = 'Model Histories'

Functions

get_model_history

get_model_history(model: models.Model) -> bool

Populate fields self.before and self.after

Pass in the model that changed and this function will read values model.before and model.after to populate the history table.

Note: Audit history expects all models to call and save to an attribute before self.__dict__ and after save to an attribute called after. Prior to calling the after, you must refresh from the database.

Parameters:

Name Type Description Default
model Model

The model to get the history for

required

Returns:

Name Type Description
True bool

History fields populated

Fail bool

History fields not populated

About:

This page forms part of our Project Centurion ERP.

Page Metadata
Version: ToDo: place files short git commit here
Date Created: 2025-05-29
Date Edited: 2025-05-28

Contribution:

Would You like to contribute to our Centurion ERP project? You can assist in the following ways:

 

ToDo: Add the page list of contributors