refactor(core): Switch to inherit from Centurion model for model TicketCommentBase
ref: #870 #865
This commit is contained in:
@ -0,0 +1,41 @@
|
||||
# Generated by Django 5.1.10 on 2025-07-13 13:28
|
||||
|
||||
import access.models.tenancy_abstract
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("access", "0021_roleaudithistory_rolecenturionmodelnote"),
|
||||
("core", "0034_alter_ticketbase_id_alter_ticketbase_organization"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="ticketcommentbase",
|
||||
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="ticketcommentbase",
|
||||
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",
|
||||
),
|
||||
),
|
||||
]
|
@ -7,11 +7,11 @@ from rest_framework.reverse import reverse
|
||||
|
||||
from access.fields import AutoCreatedField, AutoLastModifiedField
|
||||
from access.models.entity import Entity
|
||||
from access.models.tenancy import TenancyObject
|
||||
|
||||
from core import exceptions as centurion_exception
|
||||
from core.lib.feature_not_used import FeatureNotUsed
|
||||
from core.lib.slash_commands import SlashCommands
|
||||
from core.models.centurion import CenturionModel
|
||||
from core.models.ticket_base import TicketBase
|
||||
from core.models.ticket.ticket_comment_category import TicketCommentCategory
|
||||
|
||||
@ -19,10 +19,16 @@ from core.models.ticket.ticket_comment_category import TicketCommentCategory
|
||||
|
||||
class TicketCommentBase(
|
||||
SlashCommands,
|
||||
TenancyObject
|
||||
CenturionModel,
|
||||
):
|
||||
|
||||
|
||||
_audit_enabled = False
|
||||
|
||||
_notes_enabled = False
|
||||
|
||||
model_notes = None
|
||||
|
||||
save_model_history: bool = False
|
||||
|
||||
|
||||
@ -63,16 +69,6 @@ class TicketCommentBase(
|
||||
|
||||
model_notes = None
|
||||
|
||||
is_global = None
|
||||
|
||||
|
||||
id = models.AutoField(
|
||||
blank = False,
|
||||
help_text = 'Comment ID Number',
|
||||
primary_key = True,
|
||||
unique = True,
|
||||
verbose_name = 'Number',
|
||||
)
|
||||
|
||||
parent = models.ForeignKey(
|
||||
'self',
|
||||
@ -257,13 +253,6 @@ class TicketCommentBase(
|
||||
|
||||
def clean(self):
|
||||
|
||||
try:
|
||||
self.organization
|
||||
|
||||
except:
|
||||
self.organization = self.ticket.organization
|
||||
|
||||
|
||||
if not self.is_template:
|
||||
|
||||
if self.is_closed and self.date_closed is None:
|
||||
@ -282,6 +271,19 @@ class TicketCommentBase(
|
||||
|
||||
|
||||
|
||||
def clean_fields(self, exclude=None):
|
||||
|
||||
try:
|
||||
self.organization
|
||||
|
||||
except:
|
||||
self.organization = self.ticket.organization
|
||||
|
||||
|
||||
return super().clean_fields(exclude)
|
||||
|
||||
|
||||
|
||||
def get_related_model(self):
|
||||
"""Recursive model Fetch
|
||||
|
||||
@ -347,11 +349,11 @@ class TicketCommentBase(
|
||||
|
||||
if self.parent:
|
||||
|
||||
url_name = '_api_v2_ticket_comment_base_sub_thread'
|
||||
url_name = '_api_ticket_comment_base_sub_thread'
|
||||
|
||||
else:
|
||||
|
||||
url_name = '_api_v2_ticket_comment_base_sub'
|
||||
url_name = '_api_ticket_comment_base_sub'
|
||||
|
||||
|
||||
if request:
|
||||
|
Reference in New Issue
Block a user