feat(settings): Change model to inherit from CenturionModel
for AppSettings model
ref: #833 #834
This commit is contained in:
@ -0,0 +1,85 @@
|
||||
# Generated by Django 5.1.9 on 2025-06-15 04:26
|
||||
|
||||
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"),
|
||||
("settings", "0012_alter_appsettings_global_organization_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="appsettings",
|
||||
name="global_organization",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
help_text="Tenant global items will be created in",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
related_name="global_organization",
|
||||
to="access.tenant",
|
||||
verbose_name="Global Tenant",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="appsettings",
|
||||
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="appsettings",
|
||||
name="owner_organization",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
help_text="Tenant the settings belong to",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="owner_organization",
|
||||
to="access.tenant",
|
||||
),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="AppSettingsAuditHistory",
|
||||
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="settings.appsettings",
|
||||
verbose_name="Model",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "App Settings History",
|
||||
"verbose_name_plural": "App Settings Histories",
|
||||
"db_table": "settings_appsettings_audithistory",
|
||||
"managed": True,
|
||||
},
|
||||
bases=("core.centurionaudit",),
|
||||
),
|
||||
]
|
@ -1,37 +1,15 @@
|
||||
from django.db import models
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from access.fields import *
|
||||
from access.fields import AutoLastModifiedField
|
||||
from access.models.tenant import Tenant
|
||||
|
||||
from core.lib.feature_not_used import FeatureNotUsed
|
||||
from core.mixins.history_save import SaveHistory
|
||||
from core.models.centurion import CenturionModel
|
||||
|
||||
|
||||
|
||||
class AppSettingsCommonFields(models.Model):
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
id = models.AutoField(
|
||||
blank=False,
|
||||
help_text = 'Id of this setting',
|
||||
primary_key=True,
|
||||
unique=True,
|
||||
verbose_name = 'ID'
|
||||
)
|
||||
|
||||
slug = None
|
||||
|
||||
created = AutoCreatedField()
|
||||
|
||||
modified = AutoLastModifiedField()
|
||||
|
||||
|
||||
|
||||
class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
class AppSettings(
|
||||
CenturionModel,
|
||||
):
|
||||
""" Application Settings
|
||||
|
||||
This model is for storing settings for the application as a whole
|
||||
@ -44,6 +22,8 @@ class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
ValidationError: When software set as global and no organization has been specified
|
||||
"""
|
||||
|
||||
_notes_enabled = False
|
||||
|
||||
class Meta:
|
||||
|
||||
ordering = [
|
||||
@ -54,14 +34,16 @@ class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
|
||||
verbose_name_plural = 'App Settings'
|
||||
|
||||
model_notes = None
|
||||
|
||||
organization = None
|
||||
|
||||
owner_organization = models.ForeignKey(
|
||||
Tenant,
|
||||
blank= True,
|
||||
help_text = 'Tenant the settings belong to',
|
||||
default = None,
|
||||
null = True,
|
||||
on_delete=models.SET_DEFAULT,
|
||||
on_delete = models.CASCADE,
|
||||
related_name = 'owner_organization'
|
||||
)
|
||||
|
||||
@ -102,15 +84,16 @@ class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
|
||||
global_organization = models.ForeignKey(
|
||||
Tenant,
|
||||
on_delete=models.SET_DEFAULT,
|
||||
on_delete = models.PROTECT,
|
||||
blank= True,
|
||||
default = None,
|
||||
help_text = 'Tenant global items will be created in',
|
||||
null = True,
|
||||
related_name = 'global_organization',
|
||||
verbose_name = 'Global Tenant'
|
||||
)
|
||||
|
||||
modified = AutoLastModifiedField()
|
||||
|
||||
table_fields: list = []
|
||||
|
||||
page_layout: list = [
|
||||
@ -142,24 +125,6 @@ class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
return self.global_organization
|
||||
|
||||
|
||||
|
||||
def get_url( self, request = None ) -> str:
|
||||
|
||||
model_name = str(self._meta.verbose_name.lower()).replace(' ', '_')
|
||||
|
||||
|
||||
if request:
|
||||
|
||||
return reverse(f"v2:_api_v2_app_settings-detail", request=request, kwargs = { 'pk': self.pk } )
|
||||
|
||||
return reverse(f"v2:_api_v2_app_settings-detail", kwargs = { 'pk': self.pk } )
|
||||
|
||||
def get_url_kwargs_notes(self):
|
||||
|
||||
return FeatureNotUsed
|
||||
|
||||
|
||||
|
||||
def clean(self):
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
@ -175,17 +140,3 @@ class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
'software_categories_is_global',
|
||||
'global_organization',
|
||||
]
|
||||
|
||||
|
||||
def save_history(self, before: dict, after: dict) -> bool:
|
||||
|
||||
from settings.models.app_settings_history import AppSettingsHistory
|
||||
|
||||
history = super().save_history(
|
||||
before = before,
|
||||
after = after,
|
||||
history_model = AppSettingsHistory,
|
||||
)
|
||||
|
||||
|
||||
return history
|
||||
|
Reference in New Issue
Block a user