feat(access): History Model for Organization added

ref: #605 #607
This commit is contained in:
2025-02-19 23:36:22 +09:30
parent 61207c55f9
commit b2f1fba86a
3 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,43 @@
# Generated by Django 5.1.5 on 2025-02-19 13:32
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('access', '0003_alter_team_organization_organizationnotes_teamnotes'),
('core', '0018_ticketcommentcategoryhistory'),
]
operations = [
migrations.CreateModel(
name='OrganizationHistory',
fields=[
('modelhistory_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.modelhistory')),
('model', models.ForeignKey(help_text='Model this note belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='history', to='access.organization', verbose_name='Model')),
],
options={
'verbose_name': 'Organization History',
'verbose_name_plural': 'Organization History',
'db_table': 'access_organization_history',
'ordering': ['-created'],
},
bases=('core.modelhistory',),
),
migrations.CreateModel(
name='TeamHistory',
fields=[
('modelhistory_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.modelhistory')),
('model', models.ForeignKey(help_text='Model this note belongs to', on_delete=django.db.models.deletion.CASCADE, related_name='history', to='access.team', verbose_name='Model')),
],
options={
'verbose_name': 'Team History',
'verbose_name_plural': 'Team History',
'db_table': 'access_team_history',
'ordering': ['-created'],
},
bases=('core.modelhistory',),
),
]

View File

@ -0,0 +1,53 @@
from django.db import models
from core.models.model_history import ModelHistory
from access.models.organization import Organization
class OrganizationHistory(
ModelHistory
):
class Meta:
db_table = 'access_organization_history'
ordering = ModelHistory._meta.ordering
verbose_name = 'Organization History'
verbose_name_plural = 'Organization History'
model = models.ForeignKey(
Organization,
blank = False,
help_text = 'Model this note belongs to',
null = False,
on_delete = models.CASCADE,
related_name = 'history',
verbose_name = 'Model',
)
table_fields: list = []
page_layout: dict = []
def get_object(self):
return self
def get_serialized_model(self, serializer_context):
model = None
from access.serializers.organization import OrganizationBaseSerializer
model = OrganizationBaseSerializer(self.model, context = serializer_context)
return model

View File

@ -1,5 +1,7 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse
# THis import only exists so that the migrations can be created
from access.models.organization_history import OrganizationHistory # pylint: disable=W0611:unused-import
from access.serializers.organization import (
Organization,
OrganizationModelSerializer,