feat(itim): Change model to inherit from CenturionModel for ClusterType model

ref: #824 #826
This commit is contained in:
2025-06-13 12:43:30 +09:30
parent 44489b308b
commit a192659c80
2 changed files with 142 additions and 31 deletions

View File

@ -0,0 +1,136 @@
# Generated by Django 5.1.9 on 2025-06-13 02:59
import access.models.tenancy_abstract
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("access", "0016_remove_tenant_slug_alter_tenant_manager_and_more"),
("core", "0033_alter_ticketcommentcategory_parent_and_more"),
("itim", "0011_remove_cluster_is_global_remove_cluster_slug_and_more"),
]
operations = [
migrations.RemoveField(
model_name="clustertype",
name="is_global",
),
migrations.RemoveField(
model_name="clustertype",
name="slug",
),
migrations.AlterField(
model_name="clustertype",
name="config",
field=models.JSONField(
blank=True,
help_text="Cluster Type Configuration that is applied to all clusters of this type",
null=True,
verbose_name="Configuration",
),
),
migrations.AlterField(
model_name="clustertype",
name="id",
field=models.AutoField(
help_text="ID of the item",
primary_key=True,
serialize=False,
unique=True,
verbose_name="ID",
),
),
migrations.AlterField(
model_name="clustertype",
name="model_notes",
field=models.TextField(
blank=True,
help_text="Tid bits of information",
null=True,
verbose_name="Notes",
),
),
migrations.AlterField(
model_name="clustertype",
name="organization",
field=models.ForeignKey(
help_text="Tenant this belongs to",
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="access.tenant",
validators=[
access.models.tenancy_abstract.TenancyAbstractModel.validatate_organization_exists
],
verbose_name="Tenant",
),
),
migrations.CreateModel(
name="ClusterTypeAuditHistory",
fields=[
(
"centurionaudit_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="core.centurionaudit",
),
),
(
"model",
models.ForeignKey(
help_text="Model this history belongs to",
on_delete=django.db.models.deletion.CASCADE,
related_name="audit_history",
to="itim.clustertype",
verbose_name="Model",
),
),
],
options={
"verbose_name": "Cluster Type History",
"verbose_name_plural": "Cluster Type Histories",
"db_table": "itim_clustertype_audithistory",
"managed": True,
},
bases=("core.centurionaudit",),
),
migrations.CreateModel(
name="ClusterTypeCenturionModelNote",
fields=[
(
"centurionmodelnote_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="core.centurionmodelnote",
),
),
(
"model",
models.ForeignKey(
help_text="Model this note belongs to",
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="itim.clustertype",
verbose_name="Model",
),
),
],
options={
"verbose_name": "Cluster Type Note",
"verbose_name_plural": "Cluster Type Notes",
"db_table": "itim_clustertype_centurionmodelnote",
"managed": True,
},
bases=("core.centurionmodelnote",),
),
]

View File

@ -2,8 +2,7 @@ import json
from django.db import models
from access.fields import *
from access.models.tenancy import TenancyObject
from access.fields import AutoLastModifiedField
from core.models.centurion import CenturionModel
@ -11,7 +10,11 @@ from itam.models.device import Device
class ClusterType(TenancyObject):
class ClusterType(
CenturionModel
):
model_tag = 'cluster_type'
class Meta:
@ -25,14 +28,6 @@ class ClusterType(TenancyObject):
verbose_name_plural = "Cluster Types"
id = models.AutoField(
blank=False,
help_text = 'ID for this cluster type',
primary_key=True,
unique=True,
verbose_name = 'ID'
)
name = models.CharField(
blank = False,
help_text = 'Name of the Cluster Type',
@ -41,20 +36,13 @@ class ClusterType(TenancyObject):
verbose_name = 'Name',
)
slug = AutoSlugField()
config = models.JSONField(
blank = True,
default = None,
help_text = 'Cluster Type Configuration that is applied to all clusters of this type',
null = True,
verbose_name = 'Configuration',
)
created = AutoCreatedField()
modified = AutoLastModifiedField()
@ -123,19 +111,6 @@ class ClusterType(TenancyObject):
return self.name
def save_history(self, before: dict, after: dict) -> bool:
from itim.models.cluster_type_history import ClusterTypeHistory
history = super().save_history(
before = before,
after = after,
history_model = ClusterTypeHistory,
)
return history
class Cluster(