feat(core): added new history model

ref: #570 #602
This commit is contained in:
2025-02-14 22:10:36 +09:30
parent 103f25be1d
commit 6f94c95221
2 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,96 @@
from django.contrib.auth.models import ContentType, User
from django.db import models
from access.fields import *
class ModelHistory(
models.Model
):
class Meta:
ordering = [
'-created'
]
verbose_name = 'History'
verbose_name_plural = 'History'
class Actions(models.IntegerChoices):
ADD = 1, 'Create'
UPDATE = 2, 'Update'
DELETE = 3, 'Delete'
id = models.AutoField(
blank=False,
help_text = 'ID for this history entry',
primary_key=True,
unique=True,
verbose_name = 'ID'
)
before = models.JSONField(
blank = True,
default = None,
help_text = 'JSON Object before Change',
null = True,
verbose_name = 'Before'
)
after = models.JSONField(
blank = True,
default = None,
help_text = 'JSON Object After Change',
null = True,
verbose_name = 'After'
)
action = models.IntegerField(
blank = False,
choices=Actions,
default=None,
help_text = 'History action performed',
null=True,
verbose_name = 'Action'
)
user = models.ForeignKey(
User,
blank= False,
help_text = 'User whom performed the action this history relates to',
null = True,
on_delete=models.DO_NOTHING,
verbose_name = 'User'
)
content_type = models.ForeignKey(
ContentType,
blank= True,
help_text = 'Model this note is for',
null = False,
on_delete=models.CASCADE,
verbose_name = 'Content Model'
)
created = AutoCreatedField()
table_fields: list = [
'created',
'action',
'content_type',
'user',
'nbsp',
[
'before',
'after'
]
]

View File

@ -73,12 +73,33 @@ A Model link is a reference to an item within the database. Supported model link
| Model | Tag |
|:---|:---:|
| cluster| `$cluster-<id>` |
| configgroups| `$config_group-<id>` |
| clustertype| `$-<id>` |
| config groups| `$config_group-<id>` |
| device| `$device-<id>` |
| devicemodel| `$-<id>` |
| devicetype| `$-<id>` |
| externallink| `$-<id>` |
| group| `$-<id>` |
| knowledgebase| `$kb-<id>` |
| knowledgebasecategory| `$-<id>` |
| manufacturer| `$-<id>` |
| modelnotes| `$-<id>` |
| operatingsystem| `$operating_system-<id>` |
| operatingsystemversion| `$-<id>` |
| organization| `$organization-<id>` |
| port| `$-<id>` |
| project| `$-<id>` |
| projectmilestone| `$-<id>` |
| projectstate| `$-<id>` |
| projecttask| `$-<id>` |
| projecttype| `$-<id>` |
| service| `$service-<id>` |
| software| `$software-<id>` |
| softwarecategory| `$-<id>` |
| softwareversion| `$-<id>` |
| team| `$team-<id>` |
| ticketcategory| `$-<id>` |
| ticketcomment| `$-<id>` |
| ticketcommentcategory| `$-<id>` |
To declare a model link use syntax `$<type>-<model id>`. i.e. for device 1, it would be `$device-1`